| {
input: {
dir: "runtime",
match: /\.(coffee|pegjs)$/
},
output: {
dir: "www/js"
},
script: {
includes: "www/includes.html",
prefix: "/js/"
},
module: {
main: "glass.js",
prefix: "./www/js/"
},
debug: "buildlog.html",
test: "glass.allTests",
addon: {
pregenerate: {
addUri: function(schema) {
var content, type, typeName, _ref2, _ref3;
_ref2 = schema.types;
for (typeName in _ref2) {
type = _ref2[typeName];
content = type.content;
if (content.extension) {
continue;
}
if ((_ref3 = content.uri) == null) {
content.uri = "global:/" + (content.path.replace(/\./g, '/'));
}
}
return schema;
}
}
}
} | {
options: {
input: {
dir: "runtime",
match: /\.(coffee|pegjs)$/
},
output: {
dir: "www/js"
},
script: {
includes: "www/includes.html",
prefix: "/js/"
},
module: {
main: "glass.js",
prefix: "./www/js/"
},
debug: "buildlog.html",
test: "glass.allTests",
addon: {
pregenerate: {
addUri: function(schema) {
var content, type, typeName, _ref2, _ref3;
_ref2 = schema.types;
for (typeName in _ref2) {
type = _ref2[typeName];
content = type.content;
if (content.extension) {
continue;
}
if ((_ref3 = content.uri) == null) {
content.uri = "global:/" + (content.path.replace(/\./g, '/'));
}
}
return schema;
}
}
},
namespace: ""
}
} | {
options: {
input: {
dir: "runtime",
match: /\.(coffee|pegjs)$/
},
output: {
dir: "www/js"
},
script: {
includes: "www/includes.html",
prefix: "/js/"
},
module: {
main: "glass.js",
prefix: "./www/js/"
},
debug: "buildlog.html",
test: "glass.allTests",
addon: {
pregenerate: {
addUri: function(schema) {
var content, type, typeName, _ref2, _ref3;
_ref2 = schema.types;
for (typeName in _ref2) {
type = _ref2[typeName];
content = type.content;
if (content.extension) {
continue;
}
if ((_ref3 = content.uri) == null) {
content.uri = "global:/" + (content.path.replace(/\./g, '/'));
}
}
return schema;
}
}
},
namespace: ""
},
types: ["runtime\\glass\\Component.coffee", "runtime\\glass\\Container.coffee", "runtime\\glass\\Expression\\_parser.pegjs", "runtime\\glass\\Expression.coffee", "runtime\\glass\\JSONMergePatch.coffee", "runtime\\glass\\JSONPointer.coffee", "runtime\\glass\\Observable.coffee", "runtime\\glass.coffee", "runtime\\String.coffee"]
} | {
options: {
input: {
dir: "runtime",
match: /\.(coffee|pegjs)$/
},
output: {
dir: "www/js"
},
script: {
includes: "www/includes.html",
prefix: "/js/"
},
module: {
main: "glass.js",
prefix: "./www/js/"
},
debug: "buildlog.html",
test: "glass.allTests",
addon: {
pregenerate: {
addUri: function(schema) {
var content, type, typeName, _ref2, _ref3;
_ref2 = schema.types;
for (typeName in _ref2) {
type = _ref2[typeName];
content = type.content;
if (content.extension) {
continue;
}
if ((_ref3 = content.uri) == null) {
content.uri = "global:/" + (content.path.replace(/\./g, '/'));
}
}
return schema;
}
}
},
namespace: ""
},
types: {
"runtime\\glass\\Component.coffee": {
source: "extends: 'Observable'
constructor: (properties) ->
@patch properties
# now site ourselves on our parent
if @parent
id = getId @
patch @parent, id, @
@
properties:
id:
description: 'string which uniquely identifies this component within its parent'
type: 'string'
parent:
description: 'the object that contains this component'
serializable: false
type: 'object'
disposed: false
dispose: -> @patch 'disposed', true
notify: (change) ->
Observable.prototype.notify.apply this, arguments
if change?.disposed
# dispose of any disposable children
for id, child of @ when child?.parent is @
child.dispose?()
# remove self from parent
if @id and @parent
patch @parent, @id, undefined
return
test:
lifecycle: ->
parent = new Component
assert not parent.id?
assert not parent.parent?
child = new Component parent:parent
# id should be automatically assigned
assert isString child.id
assert parent is child.parent
assert parent[child.id] is child
assert parent.hasOwnProperty child.id
parent.dispose()
assert child.disposed is true
assert not parent.hasOwnProperty child.id
nonEnumerability: ->
visibleKeys = (key for key of new Component)
assertEquals visibleKeys, []",
input: "runtime\\glass\\Component.coffee"
},
"runtime\\glass\\Container.coffee": {
source: "extends: 'Observable'
properties:
watch: ->
unwatch: ->
",
input: "runtime\\glass\\Container.coffee"
},
"runtime\\glass\\Expression\\_parser.pegjs": {
source: "{
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e,array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++)
array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
}
start = expression
expression = conditional
conditional = e:or args:(\"?\" b:expression \":\" c:expression {return [b,c];})* {
while (args.length > 0) {
e = expr(\"?:\", [e].concat(args.pop()));
}
return e;
}
or = a:and b:((\"or\") and)* { return joinLeft(a,b); }
and = a:equality b:((\"and\") equality)* { return joinLeft(a,b); }
equality = a:rel b:((\"==\" / \"!=\") rel)* { return joinLeft(a,b); }
rel = a:sum b:((\"<=\" / \">=\" / \"<\" / \">\") sum)* { return joinLeft(a,b); }
sum = a:product b:((\"+\" / \"-\") product)* { return joinLeft(a,b); }
product = a:not b:((\"*\" / \"div\" / \"mod\") not)* { return joinLeft(a,b); }
not = ops:(s op:(\"!\" / \"~\" / \"+\" / \"-\") { return op; })* b:primary { return unaryRight(ops,b); }
primary = s a:(group / literal / path) s { return a; }
group = \"(\" a:expression \")\" { return a; }
literal = s a:(boolean / number / string / array / object) s { return a; }
boolean = a:(\"true\" / \"false\") { return a == \"true\"; }
number = a:([0-9]+ (\".\" [0-9]+)?) { return parseFloat(toString(a)); }
hex = [a-fA-F0-9]
// as per JSON http://www.json.org
string = a:( '\"' (
[\\u0000-\\u0021\\u0023-\\u005c\\u005e-\\uffff] // all unicode chars except \\ and \"
/ (\"\\\\\" (\"\\\"\" / \"\\\\\" / \"\\/\" / \"b\" / \"f\" / \"n\" / \"r\" / \"t\" / (\"u\" hex hex hex hex)))
)* '\"' )
{ return JSON.parse(toString(a)); }
array = \"[\" a:values \"]\" { return expr(\"array\", a); }
values = first:expression? args:(\",\" b:expression {return b;})* {
if (first != \"\") { args.unshift(first); } return args;
}
object = \"{\" a:keyvalues \"}\" { return expr(\"object\", a); }
keyvalue = s a:string s \":\" b:expression { return [a,b]; }
keyvalues = first:keyvalue? rest:(\",\" b:keyvalue {return b;})* {
if (first) { rest.unshift(first); } return rest;
}
ref = a:(\"//\" / \"/\" / \"$\" / \"**\" / \"*\" / \"..\" / \".\") b:slashProperty? {
e = expr(a); if (b) { b.args.unshift(e); e = b; } return e;
}
/ a:id { return expr(\"ref\", [a]); }
id = a:[a-z_]+ b:[a-z_0-9]* { return a.join('') + b.join(''); }
property = \"/\" a:slashProperty { return a; }
/ \"{\" a:expression \"}\" { return expr(\"{}\", [a]); } // locally scoped expression
/ \"[\" a:expression \"]\" { return expr(\"[]\", [a]); } // predicate
slashProperty = a:(id/number/string) { return expr(\"/\", [a]); }
/ a:(\"..\" / \"*\") { return expr(a, []); }
s \"space\" = [ ]* { return ''; }
path = a:root b:step* {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
}
root = a:implicitDotRoot b:dotStep? { return joinPath(a,b); }
/ explicitDotRoot
step = \".\" a:dotStep { return a; }
/ noDotStep
implicitDotRoot = \"/\" { return expr(\"root\"); }
/ \"@\" { return expr(\"this\"); }
/ \".\" a:\".\"+ { return expr(\"ancestor\", [a.length]); }
explicitDotRoot = a:id { return expr(\"ref\", [a]); }
/ \"*\" { return expr(\"values\", []); }
dotStep = a:(id / string / number) { return expr(\"get\", [a]); }
/ \"*\" { return expr(\"values\", []); }
noDotStep = \"{\" a:expression \"}\" { return expr(\"eval\", [a]); }
/ \"[\" a:expression \"]\" { return expr(\"pred\", [a]); }
/ \"(\" a:values \")\" { return expr(\"call\", [a]); }
",
input: "runtime\\glass\\Expression\\_parser.pegjs"
},
"runtime\\glass\\Expression.coffee": {
source: "constructor: (op, args) ->
@op = op
@args = args if args?
@
properties:
op:
type: 'string'
args:
type: 'array'
test: ->
return
peg = require 'pegjs'
fs = require 'fs'
parserSource = fs.readFileSync 'runtime/glass/Expression/_parser.pegjs', 'utf8'
parser = peg.buildParser parserSource
tests =
\"a.b.c\": {op:\"get\",args:[{op:\"get\",args:[{op:\"ref\",args:[\"a\"]},\"b\"]},\"c\"]}
\"a.1\": {op:\"get\",args:[{op:\"ref\",args:[\"a\"]},1]}
\"true\": true
\"false\": false
\"45.8\": 45.8
\"(45.8)\": 45.8
\"((45.8))\": 45.8
\"alpha\": {op:\"ref\",args:[\"alpha\"]}
\"35 + true * 2\": {op:\"+\", args:[35, {op:\"*\", args:[true,2]}]}
\" 5 * ( 2 + 2 ) \": {op:\"*\", args:[5, {op:\"+\", args:[2,2]}]}
\" ! ! true\": {op:\"!\",args:[{op:\"!\",args:[true]}]}
\"5 + -x\": {op:\"+\",args:[5,{op:\"-\",args:[{op:\"ref\",args:[\"x\"]}]}]}
\"true == 5 >= 2\": {op:\"==\",args:[true,{op:\">=\",args:[5,2]}]}
\"1 or 2 and 3\": {op:\"or\",args:[1,{op:\"and\",args:[2,3]}]}
\"1 ? 2 : 3\": {op:\"?:\",args:[1,2,3]}
\"1 ? 2 : 3 ? 4 : 5\" : {op:\"?:\",args:[1,2,{op:\"?:\",args:[3,4,5]}]}
\"a()(1,2)\" : {op:\"call\",args:[{op:\"call\",args:[{op:\"ref\",args:[\"a\"]},[]]},[1,2]]}
\"@\" : {op:\"this\"}
\"@foo\" : {op:\"get\",args:[{op:\"this\"},\"foo\"]}
'\"hello\"': \"hello\"
'\"\\\\t\\
\\
\\\\b\\\\\\\\foo\\\\\\/\"' : \"\\t
\\b\\\\foo\\/\"
\"[]\": {op:\"array\",args:[]}
\"[1,2]\": {op:\"array\",args:[1,2]}
\"[1+2]\": {op:\"array\",args:[{op:\"+\",args:[1,2]}]}
\"{}\": {op:\"object\",args:[]}
'{\"a\":2}': {op:\"object\",args:[[\"a\",2]]}
'{\"a\":2,\"b\":1+2}': {op:\"object\",args:[[\"a\",2],[\"b\",{op:\"+\",args:[1,2]}]]}
'@\"alpha\"': {op:\"get\",args:[{op:\"this\"},\"alpha\"]}
'*': {op:\"values\",args:[]}
'*.*': {op:\"values\",args:[{op:\"values\",args:[]}]}
\"foo.*\": {op:\"values\",args:[{op:\"ref\",args:[\"foo\"]}]}
\"..\": {op:\"ancestor\",args:[1]}
\"...\": {op:\"ancestor\",args:[2]}
\"@*{1+2}\": {op:\"eval\",args:[{op:\"values\",args:[{op:\"this\"}]},{op:\"+\",args:[1,2]}]}
\"/\": {op:\"root\"}
\"/foo\": {op:\"get\",args:[{op:\"root\"},\"foo\"]}
\"/*\": {op:\"values\",args:[{op:\"root\"}]}
for text, expected of tests
result = parser.parse text
if JSON.stringify(result) is JSON.stringify(expected)
console.log 'Pass: ' + text
else
console.log text, JSON.stringify result
return
",
input: "runtime\\glass\\Expression.coffee"
},
"runtime\\glass\\JSONMergePatch.coffee": {
source: "
# applies a patch to the target object and returns the resulting target
apply: (target, patch) ->
if target? and target isnt patch and isPlainObject(patch) and not isPrimitive(target)
for key, value of patch
if value is undefined
delete target[key]
else
target[key] = apply target[key], patch[key]
return target
else
return patch
# (path1, path2, path3.., patch) ->
create: ->
if arguments.length is 1
return arguments[0]
result = {}
current = result
for arg, i in arguments when i + 1 < arguments.length
last = i + 2 is arguments.length
current = current[arg] = if last then arguments[arguments.length-1] else {}
result
test: ->
assertEquals {a:{b:12}}, create 'a', 'b', 12
assertEquals {a:3}, apply({a:1,b:2}, {a:3,b:undefined})
",
input: "runtime\\glass\\JSONMergePatch.coffee"
},
"runtime\\glass\\JSONPointer.coffee": {
source: "# json pointer implementation as per
# http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-05
_decodeStep: (step) -> step.replace(/~1/g, '/').replace(/~0/g, '~')
_getLastStep: (pointer) ->
_decodeStep pointer.substring(pointer.lastIndexOf('/') + 1)
_getParent: (pointer) ->
if not pointer?.length
null
else
pointer.substring(0, pointer.lastIndexOf('/'))
toArray: (pointer) ->
for step in pointer.substring(1).split('/')
_decodeStep step
get: (doc, pointer) ->
value = doc
if pointer.length
path = toArray pointer
for step in path when value?
value = value[step]
value
set: (doc, pointer, value) ->
parentPointer = _getParent pointer
if parentPointer?
parent = get doc, parentPointer
lastStep = _getLastStep pointer
parent[lastStep] = value
value
test: ->
assertEquals _getParent(\"/a/b/c\"), \"/a/b\"
assertEquals _getParent(\"/a\"), \"\"
assertEquals _getParent(\"\"), null
assertEquals _getLastStep(\"/a/b/c\"), \"c\"
assertEquals _getLastStep(\"/a~0~1\"), \"a~/\"
assertEquals _getLastStep(\"\"), \"\"
# tests as per spec
doc = {
\"foo\": [\"bar\", \"baz\"],
\"\": 0,
\"a/b\": 1,
\"c%d\": 2,
\"e^f\": 3,
\"g|h\": 4,
\"i\\\\j\": 5,
\"k\\\"l\": 6,
\" \": 7,
\"m~n\": 8
}
assertEquals get(doc, \"\"), doc
assertEquals get(doc, \"/foo\"), [\"bar\", \"baz\"]
assertEquals get(doc, \"/foo/0\"), \"bar\"
assertEquals get(doc, \"/\"), 0
assertEquals get(doc, \"/a~1b\"), 1
assertEquals get(doc, \"/c%d\"), 2
assertEquals get(doc, \"/e^f\"), 3
assertEquals get(doc, \"/g|h\"), 4
assertEquals get(doc, \"/i\\\\j\"), 5
assertEquals get(doc, \"/k\\\"l\"), 6
assertEquals get(doc, \"/ \"), 7
assertEquals get(doc, \"/m~0n\"), 8
# now test set
assertEquals set(doc, \"/\", 10), 10
assertEquals doc[\"\"], 10
assertEquals set(doc, \"/foo/0\", 10), 10
assertEquals doc.foo[0], 10",
input: "runtime\\glass\\JSONPointer.coffee"
},
"runtime\\glass\\Observable.coffee": {
source: "properties:
is: (type) -> @constructor.implements[type.path ? type] is true
watchers:
serializable: false
watch: (property, watcher) ->
if isFunction property
watcher = property
property = ''
id = getId watcher
@patch 'watchers', property, id, watcher
# returns a function which will remove the watch
=> @patch 'watchers', property, getId(watcher), undefined
patch: (change) ->
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
try
JSONMergePatch.apply this, change
catch e
console.log e
finally
@notify change
return
notify: (change) ->
if @watchers?
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
for property, watchers of @watchers
if property.length is 0 or change.hasOwnProperty property
changeArg = if property.length is 0 then change else change[property]
for id, watcher of watchers
watcher this, changeArg
return
toJSON: ->
values =
class: @constructor.path
# serialize statically defined properties
for name, property of @constructor.properties
value = @[name]
if property.serializable isnt false and not isFunction(value)
values[name] = value
# serialize custom properties if allowed by schema
if @constructor.additionalProperties isnt false
for own name, value of @ when not isPrivate name
values[name] = value
values
toString: -> @toJSON()
test:
toJSON: ->
# I need this test later
# on a class that actually has serializable properties
a = new Observable
a.x = 12
a.y = ->
a.z = true
assertEquals a, {class:'glass.Observable', x:12,z:true}
watchAll: ->
# we should actually be able to watch ourselves get added to watchers
# this is very meta.
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch watcher
# now make sure we were called with our own watcher
assert watchArgs[0] is a
assert watchArgs[1]?.watchers?[\"\"]?
# reset watchArgs, and watch something else
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assertEquals a.a, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {a:{b:3}}
# now unwatch
unwatch()
# make sure universal watcher is now empty
assertEquals a.watchers[\"\"], {}
# now reset and do a new event, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
watchProperty: ->
# watch a property
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch \"foo\", watcher
# now make sure we were not called
assert watchArgs.length is 0
# reset watchArgs, and watch something else
a.patch \"foo\", \"b\", 3
assertEquals a.foo, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {b:3}
# now reset and do a different property, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
# now unwatch
unwatch()
# make sure we no longer see foo
watchArgs.length = 0
a.patch \"foo\", \"b\", 4
assert watchArgs.length is 0
",
input: "runtime\\glass\\Observable.coffee"
},
"runtime\\glass.coffee": {
source: "require:
\tString: true
# runtime type tests
isFunction: (object) -> object? and typeof object is 'function'
isString: (object) -> object?.constructor is String
isArray: (object) -> Array.isArray object
isBoolean: (object) -> object? and typeof object is 'boolean'
isNumber: (object) -> object? and typeof object is 'number'
isObject: (object) -> typeof object is 'object'
isPlainObject: (object) -> object?.constructor is Object
isPrototype: (object) -> object? and object is object.constructor.prototype
isDate: (object) -> object?.constructor is Date
isPrimitive: (object) -> isString(object) or isBoolean(object) or isNumber(object) or isDate(object)
isPrivate: (property) -> property?[0] is '_'
# generic utility functions
values: (object) -> (value for key, value of object)
# generic patch method, uses patch method built into object if present
patch: (target, pathAndPatch...) ->
patch = JSONMergePatch.create.apply null, pathAndPatch
if isFunction target?.patch
target.patch patch
else
glass.JSONMergePatch.apply target, patch
# testing assertions
_getStackLocationInfo: (e, depth) ->
line = e.stack?.split('
')[depth]
return null unless line?
match = /\\(([\\w\\W]*?):(\\d+):(\\d+)\\)/.exec line
return {
file: match[1]
line: parseInt match[2]
column: parseInt match[3]
}
_throwAssertionFailure: (message) ->
try
throw new Error \"Assertion failed: \" + message
catch e
info = _getStackLocationInfo e, 3
if info?
_dumpFile info.file, info.line - 2, info.line + 2, info.line
throw e
_dumpFile: (file, from=1, to, highlight) ->
fs = require 'fs'
return unless fs?
try
content = fs.readFileSync(file).toString()
catch e
content = \"Source not found: #{e}\"
console.log '------------------------------------------------'
console.log file
console.log '------------------------------------------------'
number = 1
if content?
lines = content.split /
|
/
to ?= lines.length
for line in lines
lineNumber = number++
if lineNumber >= from and lineNumber <= to
num = String lineNumber
while num.length < 3
num += ' '
if lineNumber is highlight
`console.log(\"\\033[91m\" + num + \": \" + line + \"\\033[0m\");`
else
`console.log(num + \": \" + line);`
console.log '------------------------------------------------'
assert: (a) ->
_throwAssertionFailure JSON.stringify(a) unless a
assertTrue: (a) ->
_throwAssertionFailure JSON.stringify(a) + \" != true\" unless a is true
assertEquals: (a, b) ->
if JSON.stringify(a) isnt JSON.stringify(b)
_throwAssertionFailure JSON.stringify(a) + ' != ' + JSON.stringify(b)
# gets a unique string identifier for any object
getId:
do: ->
counter = 0
(a) ->
if a is null
return '__null__'
if a is undefined
return '__undefined__'
if typeof a is 'object' or typeof a is 'function'
return a.id ?= '__' + (counter++) + '__'
# 12 == \"12\" under this technique
return a.toString()
getType: (path) ->
array = if isArray path then path else path.split '.'
value = global
for step in path when value?
value = value[step]
throw new Error \"Type not found: #{path}\" unless isFunction value
value
test:
values: ->
assertEquals values({a:1,b:3,c:2}), [1,3,2]
patch: ->
x = {a:{foo:1,bar:3},b:2}
patch x, 'a', 'foo', 5
assertEquals x.a.foo, 5
",
input: "runtime\\glass.coffee"
},
"runtime\\String.coffee": {
source: "extension: true
properties:
\tstartsWith: (s) -> @slice(0,s.length) is s
\tendsWith: (s) -> @slice(-s.length) is s
\tcontains: (s) -> @indexOf(s) >= 0
\ttoArray: () -> @split ''",
input: "runtime\\String.coffee"
}
}
} | {
options: {
input: {
dir: "runtime",
match: /\.(coffee|pegjs)$/
},
output: {
dir: "www/js"
},
script: {
includes: "www/includes.html",
prefix: "/js/"
},
module: {
main: "glass.js",
prefix: "./www/js/"
},
debug: "buildlog.html",
test: "glass.allTests",
addon: {
pregenerate: {
addUri: function(schema) {
var content, type, typeName, _ref2, _ref3;
_ref2 = schema.types;
for (typeName in _ref2) {
type = _ref2[typeName];
content = type.content;
if (content.extension) {
continue;
}
if ((_ref3 = content.uri) == null) {
content.uri = "global:/" + (content.path.replace(/\./g, '/'));
}
}
return schema;
}
}
},
namespace: ""
},
types: {
"runtime\\glass\\Component.coffee": {
source: "extends: 'Observable'
constructor: (properties) ->
@patch properties
# now site ourselves on our parent
if @parent
id = getId @
patch @parent, id, @
@
properties:
id:
description: 'string which uniquely identifies this component within its parent'
type: 'string'
parent:
description: 'the object that contains this component'
serializable: false
type: 'object'
disposed: false
dispose: -> @patch 'disposed', true
notify: (change) ->
Observable.prototype.notify.apply this, arguments
if change?.disposed
# dispose of any disposable children
for id, child of @ when child?.parent is @
child.dispose?()
# remove self from parent
if @id and @parent
patch @parent, @id, undefined
return
test:
lifecycle: ->
parent = new Component
assert not parent.id?
assert not parent.parent?
child = new Component parent:parent
# id should be automatically assigned
assert isString child.id
assert parent is child.parent
assert parent[child.id] is child
assert parent.hasOwnProperty child.id
parent.dispose()
assert child.disposed is true
assert not parent.hasOwnProperty child.id
nonEnumerability: ->
visibleKeys = (key for key of new Component)
assertEquals visibleKeys, []",
input: "runtime\\glass\\Component.coffee",
content: {
extends: "Observable",
constructor: function(properties) {
var id;
this.patch(properties);
if (this.parent) {
id = getId(this);
patch(this.parent, id, this);
}
return this;
},
properties: {
id: {
description: "string which uniquely identifies this component within its parent",
type: "string"
},
parent: {
description: "the object that contains this component",
serializable: false,
type: "object"
},
disposed: false,
dispose: function() {
return this.patch('disposed', true);
},
notify: function(change) {
var child, id;
Observable.prototype.notify.apply(this, arguments);
if (change != null ? change.disposed: void 0) {
for (id in this) {
child = this[id];
if ((child != null ? child.parent: void 0) === this) {
if (typeof child.dispose === "function") {
child.dispose();
}
}
}
if (this.id && this.parent) {
patch(this.parent, this.id, void 0);
}
}
}
},
test: {
lifecycle: function() {
var child, parent;
parent = new Component;
assert(!(parent.id != null));
assert(!(parent.parent != null));
child = new Component({
parent: parent
});
assert(isString(child.id));
assert(parent === child.parent);
assert(parent[child.id] === child);
assert(parent.hasOwnProperty(child.id));
parent.dispose();
assert(child.disposed === true);
return assert(!parent.hasOwnProperty(child.id));
},
nonEnumerability: function() {
var key, visibleKeys;
visibleKeys = (function() {
var _results;
_results = [];
for (key in new Component) {
_results.push(key);
}
return _results;
})();
return assertEquals(visibleKeys, []);
}
}
}
},
"runtime\\glass\\Container.coffee": {
source: "extends: 'Observable'
properties:
watch: ->
unwatch: ->
",
input: "runtime\\glass\\Container.coffee",
content: {
extends: "Observable",
properties: {
watch: function() {},
unwatch: function() {}
}
}
},
"runtime\\glass\\Expression\\_parser.pegjs": {
source: "{
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e,array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++)
array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
}
start = expression
expression = conditional
conditional = e:or args:(\"?\" b:expression \":\" c:expression {return [b,c];})* {
while (args.length > 0) {
e = expr(\"?:\", [e].concat(args.pop()));
}
return e;
}
or = a:and b:((\"or\") and)* { return joinLeft(a,b); }
and = a:equality b:((\"and\") equality)* { return joinLeft(a,b); }
equality = a:rel b:((\"==\" / \"!=\") rel)* { return joinLeft(a,b); }
rel = a:sum b:((\"<=\" / \">=\" / \"<\" / \">\") sum)* { return joinLeft(a,b); }
sum = a:product b:((\"+\" / \"-\") product)* { return joinLeft(a,b); }
product = a:not b:((\"*\" / \"div\" / \"mod\") not)* { return joinLeft(a,b); }
not = ops:(s op:(\"!\" / \"~\" / \"+\" / \"-\") { return op; })* b:primary { return unaryRight(ops,b); }
primary = s a:(group / literal / path) s { return a; }
group = \"(\" a:expression \")\" { return a; }
literal = s a:(boolean / number / string / array / object) s { return a; }
boolean = a:(\"true\" / \"false\") { return a == \"true\"; }
number = a:([0-9]+ (\".\" [0-9]+)?) { return parseFloat(toString(a)); }
hex = [a-fA-F0-9]
// as per JSON http://www.json.org
string = a:( '\"' (
[\\u0000-\\u0021\\u0023-\\u005c\\u005e-\\uffff] // all unicode chars except \\ and \"
/ (\"\\\\\" (\"\\\"\" / \"\\\\\" / \"\\/\" / \"b\" / \"f\" / \"n\" / \"r\" / \"t\" / (\"u\" hex hex hex hex)))
)* '\"' )
{ return JSON.parse(toString(a)); }
array = \"[\" a:values \"]\" { return expr(\"array\", a); }
values = first:expression? args:(\",\" b:expression {return b;})* {
if (first != \"\") { args.unshift(first); } return args;
}
object = \"{\" a:keyvalues \"}\" { return expr(\"object\", a); }
keyvalue = s a:string s \":\" b:expression { return [a,b]; }
keyvalues = first:keyvalue? rest:(\",\" b:keyvalue {return b;})* {
if (first) { rest.unshift(first); } return rest;
}
ref = a:(\"//\" / \"/\" / \"$\" / \"**\" / \"*\" / \"..\" / \".\") b:slashProperty? {
e = expr(a); if (b) { b.args.unshift(e); e = b; } return e;
}
/ a:id { return expr(\"ref\", [a]); }
id = a:[a-z_]+ b:[a-z_0-9]* { return a.join('') + b.join(''); }
property = \"/\" a:slashProperty { return a; }
/ \"{\" a:expression \"}\" { return expr(\"{}\", [a]); } // locally scoped expression
/ \"[\" a:expression \"]\" { return expr(\"[]\", [a]); } // predicate
slashProperty = a:(id/number/string) { return expr(\"/\", [a]); }
/ a:(\"..\" / \"*\") { return expr(a, []); }
s \"space\" = [ ]* { return ''; }
path = a:root b:step* {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
}
root = a:implicitDotRoot b:dotStep? { return joinPath(a,b); }
/ explicitDotRoot
step = \".\" a:dotStep { return a; }
/ noDotStep
implicitDotRoot = \"/\" { return expr(\"root\"); }
/ \"@\" { return expr(\"this\"); }
/ \".\" a:\".\"+ { return expr(\"ancestor\", [a.length]); }
explicitDotRoot = a:id { return expr(\"ref\", [a]); }
/ \"*\" { return expr(\"values\", []); }
dotStep = a:(id / string / number) { return expr(\"get\", [a]); }
/ \"*\" { return expr(\"values\", []); }
noDotStep = \"{\" a:expression \"}\" { return expr(\"eval\", [a]); }
/ \"[\" a:expression \"]\" { return expr(\"pred\", [a]); }
/ \"(\" a:values \")\" { return expr(\"call\", [a]); }
",
input: "runtime\\glass\\Expression\\_parser.pegjs"
},
"runtime\\glass\\Expression.coffee": {
source: "constructor: (op, args) ->
@op = op
@args = args if args?
@
properties:
op:
type: 'string'
args:
type: 'array'
test: ->
return
peg = require 'pegjs'
fs = require 'fs'
parserSource = fs.readFileSync 'runtime/glass/Expression/_parser.pegjs', 'utf8'
parser = peg.buildParser parserSource
tests =
\"a.b.c\": {op:\"get\",args:[{op:\"get\",args:[{op:\"ref\",args:[\"a\"]},\"b\"]},\"c\"]}
\"a.1\": {op:\"get\",args:[{op:\"ref\",args:[\"a\"]},1]}
\"true\": true
\"false\": false
\"45.8\": 45.8
\"(45.8)\": 45.8
\"((45.8))\": 45.8
\"alpha\": {op:\"ref\",args:[\"alpha\"]}
\"35 + true * 2\": {op:\"+\", args:[35, {op:\"*\", args:[true,2]}]}
\" 5 * ( 2 + 2 ) \": {op:\"*\", args:[5, {op:\"+\", args:[2,2]}]}
\" ! ! true\": {op:\"!\",args:[{op:\"!\",args:[true]}]}
\"5 + -x\": {op:\"+\",args:[5,{op:\"-\",args:[{op:\"ref\",args:[\"x\"]}]}]}
\"true == 5 >= 2\": {op:\"==\",args:[true,{op:\">=\",args:[5,2]}]}
\"1 or 2 and 3\": {op:\"or\",args:[1,{op:\"and\",args:[2,3]}]}
\"1 ? 2 : 3\": {op:\"?:\",args:[1,2,3]}
\"1 ? 2 : 3 ? 4 : 5\" : {op:\"?:\",args:[1,2,{op:\"?:\",args:[3,4,5]}]}
\"a()(1,2)\" : {op:\"call\",args:[{op:\"call\",args:[{op:\"ref\",args:[\"a\"]},[]]},[1,2]]}
\"@\" : {op:\"this\"}
\"@foo\" : {op:\"get\",args:[{op:\"this\"},\"foo\"]}
'\"hello\"': \"hello\"
'\"\\\\t\\
\\
\\\\b\\\\\\\\foo\\\\\\/\"' : \"\\t
\\b\\\\foo\\/\"
\"[]\": {op:\"array\",args:[]}
\"[1,2]\": {op:\"array\",args:[1,2]}
\"[1+2]\": {op:\"array\",args:[{op:\"+\",args:[1,2]}]}
\"{}\": {op:\"object\",args:[]}
'{\"a\":2}': {op:\"object\",args:[[\"a\",2]]}
'{\"a\":2,\"b\":1+2}': {op:\"object\",args:[[\"a\",2],[\"b\",{op:\"+\",args:[1,2]}]]}
'@\"alpha\"': {op:\"get\",args:[{op:\"this\"},\"alpha\"]}
'*': {op:\"values\",args:[]}
'*.*': {op:\"values\",args:[{op:\"values\",args:[]}]}
\"foo.*\": {op:\"values\",args:[{op:\"ref\",args:[\"foo\"]}]}
\"..\": {op:\"ancestor\",args:[1]}
\"...\": {op:\"ancestor\",args:[2]}
\"@*{1+2}\": {op:\"eval\",args:[{op:\"values\",args:[{op:\"this\"}]},{op:\"+\",args:[1,2]}]}
\"/\": {op:\"root\"}
\"/foo\": {op:\"get\",args:[{op:\"root\"},\"foo\"]}
\"/*\": {op:\"values\",args:[{op:\"root\"}]}
for text, expected of tests
result = parser.parse text
if JSON.stringify(result) is JSON.stringify(expected)
console.log 'Pass: ' + text
else
console.log text, JSON.stringify result
return
",
input: "runtime\\glass\\Expression.coffee",
content: {
constructor: function(op, args) {
this.op = op;
if (args != null) {
this.args = args;
}
return this;
},
properties: {
op: {
type: "string"
},
args: {
type: "array"
}
},
test: function() {
var expected, fs, parser, parserSource, peg, result, tests, text;
return;
peg = require('pegjs');
fs = require('fs');
parserSource = fs.readFileSync('runtime/glass/Expression/_parser.pegjs', 'utf8');
parser = peg.buildParser(parserSource);
tests = {
"a.b.c": {
op: "get",
args: [{
op: "get",
args: [{
op: "ref",
args: ["a"]
},
"b"]
},
"c"]
},
"a.1": {
op: "get",
args: [{
op: "ref",
args: ["a"]
},
1]
},
"true": true,
"false": false,
"45.8": 45.8,
"(45.8)": 45.8,
"((45.8))": 45.8,
"alpha": {
op: "ref",
args: ["alpha"]
},
"35 + true * 2": {
op: "+",
args: [35, {
op: "*",
args: [true, 2]
}]
},
" 5 * ( 2 + 2 ) ": {
op: "*",
args: [5, {
op: "+",
args: [2, 2]
}]
},
" ! ! true": {
op: "!",
args: [{
op: "!",
args: [true]
}]
},
"5 + -x": {
op: "+",
args: [5, {
op: "-",
args: [{
op: "ref",
args: ["x"]
}]
}]
},
"true == 5 >= 2": {
op: "==",
args: [true, {
op: ">=",
args: [5, 2]
}]
},
"1 or 2 and 3": {
op: "or",
args: [1, {
op: "and",
args: [2, 3]
}]
},
"1 ? 2 : 3": {
op: "?:",
args: [1, 2, 3]
},
"1 ? 2 : 3 ? 4 : 5": {
op: "?:",
args: [1, 2, {
op: "?:",
args: [3, 4, 5]
}]
},
"a()(1,2)": {
op: "call",
args: [{
op: "call",
args: [{
op: "ref",
args: ["a"]
},
[]]
},
[1, 2]]
},
"@": {
op: "this"
},
"@foo": {
op: "get",
args: [{
op: "this"
},
"foo"]
},
'"hello"': "hello",
'"\\t
\\b\\\\foo\\\/"': "\t
\b\\foo\/",
"[]": {
op: "array",
args: []
},
"[1,2]": {
op: "array",
args: [1, 2]
},
"[1+2]": {
op: "array",
args: [{
op: "+",
args: [1, 2]
}]
},
"{}": {
op: "object",
args: []
},
'{"a":2}': {
op: "object",
args: [["a", 2]]
},
'{"a":2,"b":1+2}': {
op: "object",
args: [["a", 2], ["b", {
op: "+",
args: [1, 2]
}]]
},
'@"alpha"': {
op: "get",
args: [{
op: "this"
},
"alpha"]
},
'*': {
op: "values",
args: []
},
'*.*': {
op: "values",
args: [{
op: "values",
args: []
}]
},
"foo.*": {
op: "values",
args: [{
op: "ref",
args: ["foo"]
}]
},
"..": {
op: "ancestor",
args: [1]
},
"...": {
op: "ancestor",
args: [2]
},
"@*{1+2}": {
op: "eval",
args: [{
op: "values",
args: [{
op: "this"
}]
},
{
op: "+",
args: [1, 2]
}]
},
"/": {
op: "root"
},
"/foo": {
op: "get",
args: [{
op: "root"
},
"foo"]
},
"/*": {
op: "values",
args: [{
op: "root"
}]
}
};
for (text in tests) {
expected = tests[text];
result = parser.parse(text);
if (JSON.stringify(result) === JSON.stringify(expected)) {
console.log('Pass: ' + text);
} else {
console.log(text, JSON.stringify(result));
}
}
}
}
},
"runtime\\glass\\JSONMergePatch.coffee": {
source: "
# applies a patch to the target object and returns the resulting target
apply: (target, patch) ->
if target? and target isnt patch and isPlainObject(patch) and not isPrimitive(target)
for key, value of patch
if value is undefined
delete target[key]
else
target[key] = apply target[key], patch[key]
return target
else
return patch
# (path1, path2, path3.., patch) ->
create: ->
if arguments.length is 1
return arguments[0]
result = {}
current = result
for arg, i in arguments when i + 1 < arguments.length
last = i + 2 is arguments.length
current = current[arg] = if last then arguments[arguments.length-1] else {}
result
test: ->
assertEquals {a:{b:12}}, create 'a', 'b', 12
assertEquals {a:3}, apply({a:1,b:2}, {a:3,b:undefined})
",
input: "runtime\\glass\\JSONMergePatch.coffee",
content: {
apply: function(target, patch) {
var key, value;
if ((target != null) && target !== patch && isPlainObject(patch) && !isPrimitive(target)) {
for (key in patch) {
value = patch[key];
if (value === void 0) {
delete target[key];
} else {
target[key] = apply(target[key], patch[key]);
}
}
return target;
} else {
return patch;
}
},
create: function() {
var arg, current, i, last, result, _i, _len;
if (arguments.length === 1) {
return arguments[0];
}
result = {};
current = result;
for (i = _i = 0, _len = arguments.length; _i < _len; i = ++_i) {
arg = arguments[i];
if (! (i + 1 < arguments.length)) {
continue;
}
last = i + 2 === arguments.length;
current = current[arg] = last ? arguments[arguments.length - 1] : {};
}
return result;
},
test: function() {
assertEquals({
a: {
b: 12
}
},
create('a', 'b', 12));
return assertEquals({
a: 3
},
apply({
a: 1,
b: 2
},
{
a: 3,
b: void 0
}));
}
}
},
"runtime\\glass\\JSONPointer.coffee": {
source: "# json pointer implementation as per
# http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-05
_decodeStep: (step) -> step.replace(/~1/g, '/').replace(/~0/g, '~')
_getLastStep: (pointer) ->
_decodeStep pointer.substring(pointer.lastIndexOf('/') + 1)
_getParent: (pointer) ->
if not pointer?.length
null
else
pointer.substring(0, pointer.lastIndexOf('/'))
toArray: (pointer) ->
for step in pointer.substring(1).split('/')
_decodeStep step
get: (doc, pointer) ->
value = doc
if pointer.length
path = toArray pointer
for step in path when value?
value = value[step]
value
set: (doc, pointer, value) ->
parentPointer = _getParent pointer
if parentPointer?
parent = get doc, parentPointer
lastStep = _getLastStep pointer
parent[lastStep] = value
value
test: ->
assertEquals _getParent(\"/a/b/c\"), \"/a/b\"
assertEquals _getParent(\"/a\"), \"\"
assertEquals _getParent(\"\"), null
assertEquals _getLastStep(\"/a/b/c\"), \"c\"
assertEquals _getLastStep(\"/a~0~1\"), \"a~/\"
assertEquals _getLastStep(\"\"), \"\"
# tests as per spec
doc = {
\"foo\": [\"bar\", \"baz\"],
\"\": 0,
\"a/b\": 1,
\"c%d\": 2,
\"e^f\": 3,
\"g|h\": 4,
\"i\\\\j\": 5,
\"k\\\"l\": 6,
\" \": 7,
\"m~n\": 8
}
assertEquals get(doc, \"\"), doc
assertEquals get(doc, \"/foo\"), [\"bar\", \"baz\"]
assertEquals get(doc, \"/foo/0\"), \"bar\"
assertEquals get(doc, \"/\"), 0
assertEquals get(doc, \"/a~1b\"), 1
assertEquals get(doc, \"/c%d\"), 2
assertEquals get(doc, \"/e^f\"), 3
assertEquals get(doc, \"/g|h\"), 4
assertEquals get(doc, \"/i\\\\j\"), 5
assertEquals get(doc, \"/k\\\"l\"), 6
assertEquals get(doc, \"/ \"), 7
assertEquals get(doc, \"/m~0n\"), 8
# now test set
assertEquals set(doc, \"/\", 10), 10
assertEquals doc[\"\"], 10
assertEquals set(doc, \"/foo/0\", 10), 10
assertEquals doc.foo[0], 10",
input: "runtime\\glass\\JSONPointer.coffee",
content: {
toArray: function(pointer) {
var step, _i, _len, _ref, _results;
_ref = pointer.substring(1).split('/');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
step = _ref[_i];
_results.push(_decodeStep(step));
}
return _results;
},
get: function(doc, pointer) {
var path, step, value, _i, _len;
value = doc;
if (pointer.length) {
path = toArray(pointer);
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
}
return value;
},
set: function(doc, pointer, value) {
var lastStep, parent, parentPointer;
parentPointer = _getParent(pointer);
if (parentPointer != null) {
parent = get(doc, parentPointer);
lastStep = _getLastStep(pointer);
parent[lastStep] = value;
}
return value;
},
test: function() {
var doc;
assertEquals(_getParent("/a/b/c"), "/a/b");
assertEquals(_getParent("/a"), "");
assertEquals(_getParent(""), null);
assertEquals(_getLastStep("/a/b/c"), "c");
assertEquals(_getLastStep("/a~0~1"), "a~/");
assertEquals(_getLastStep(""), "");
doc = {
"foo": ["bar", "baz"],
"": 0,
"a/b": 1,
"c%d": 2,
"e^f": 3,
"g|h": 4,
"i\\j": 5,
"k\"l": 6,
" ": 7,
"m~n": 8
};
assertEquals(get(doc, ""), doc);
assertEquals(get(doc, "/foo"), ["bar", "baz"]);
assertEquals(get(doc, "/foo/0"), "bar");
assertEquals(get(doc, "/"), 0);
assertEquals(get(doc, "/a~1b"), 1);
assertEquals(get(doc, "/c%d"), 2);
assertEquals(get(doc, "/e^f"), 3);
assertEquals(get(doc, "/g|h"), 4);
assertEquals(get(doc, "/i\\j"), 5);
assertEquals(get(doc, "/k\"l"), 6);
assertEquals(get(doc, "/ "), 7);
assertEquals(get(doc, "/m~0n"), 8);
assertEquals(set(doc, "/", 10), 10);
assertEquals(doc[""], 10);
assertEquals(set(doc, "/foo/0", 10), 10);
return assertEquals(doc.foo[0], 10);
}
}
},
"runtime\\glass\\Observable.coffee": {
source: "properties:
is: (type) -> @constructor.implements[type.path ? type] is true
watchers:
serializable: false
watch: (property, watcher) ->
if isFunction property
watcher = property
property = ''
id = getId watcher
@patch 'watchers', property, id, watcher
# returns a function which will remove the watch
=> @patch 'watchers', property, getId(watcher), undefined
patch: (change) ->
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
try
JSONMergePatch.apply this, change
catch e
console.log e
finally
@notify change
return
notify: (change) ->
if @watchers?
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
for property, watchers of @watchers
if property.length is 0 or change.hasOwnProperty property
changeArg = if property.length is 0 then change else change[property]
for id, watcher of watchers
watcher this, changeArg
return
toJSON: ->
values =
class: @constructor.path
# serialize statically defined properties
for name, property of @constructor.properties
value = @[name]
if property.serializable isnt false and not isFunction(value)
values[name] = value
# serialize custom properties if allowed by schema
if @constructor.additionalProperties isnt false
for own name, value of @ when not isPrivate name
values[name] = value
values
toString: -> @toJSON()
test:
toJSON: ->
# I need this test later
# on a class that actually has serializable properties
a = new Observable
a.x = 12
a.y = ->
a.z = true
assertEquals a, {class:'glass.Observable', x:12,z:true}
watchAll: ->
# we should actually be able to watch ourselves get added to watchers
# this is very meta.
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch watcher
# now make sure we were called with our own watcher
assert watchArgs[0] is a
assert watchArgs[1]?.watchers?[\"\"]?
# reset watchArgs, and watch something else
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assertEquals a.a, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {a:{b:3}}
# now unwatch
unwatch()
# make sure universal watcher is now empty
assertEquals a.watchers[\"\"], {}
# now reset and do a new event, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
watchProperty: ->
# watch a property
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch \"foo\", watcher
# now make sure we were not called
assert watchArgs.length is 0
# reset watchArgs, and watch something else
a.patch \"foo\", \"b\", 3
assertEquals a.foo, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {b:3}
# now reset and do a different property, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
# now unwatch
unwatch()
# make sure we no longer see foo
watchArgs.length = 0
a.patch \"foo\", \"b\", 4
assert watchArgs.length is 0
",
input: "runtime\\glass\\Observable.coffee",
content: {
properties: {
is: function(type) {
var _ref;
return this.constructor["implements"][(_ref = type.path) != null ? _ref: type] === true;
},
watchers: {
serializable: false
},
watch: function(property, watcher) {
var id, _this = this;
if (isFunction(property)) {
watcher = property;
property = '';
}
id = getId(watcher);
this.patch('watchers', property, id, watcher);
return function() {
return _this.patch('watchers', property, getId(watcher), void 0);
};
},
patch: function(change) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
try {
JSONMergePatch.apply(this, change);
} catch(e) {
console.log(e);
} finally {
this.notify(change);
}
},
notify: function(change) {
var changeArg, id, property, watcher, watchers, _ref;
if (this.watchers != null) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
_ref = this.watchers;
for (property in _ref) {
watchers = _ref[property];
if (property.length === 0 || change.hasOwnProperty(property)) {
changeArg = property.length === 0 ? change: change[property];
for (id in watchers) {
watcher = watchers[id];
watcher(this, changeArg);
}
}
}
}
},
toJSON: function() {
var name, property, value, values, _ref;
values = {
"class": this.constructor.path
};
_ref = this.constructor.properties;
for (name in _ref) {
property = _ref[name];
value = this[name];
if (property.serializable !== false && !isFunction(value)) {
values[name] = value;
}
}
if (this.constructor.additionalProperties !== false) {
for (name in this) {
if (!__hasProp.call(this, name)) continue;
value = this[name];
if (!isPrivate(name)) {
values[name] = value;
}
}
}
return values;
},
toString: function() {
return this.toJSON();
}
},
test: {
toJSON: function() {
var a;
a = new Observable;
a.x = 12;
a.y = function() {};
a.z = true;
return assertEquals(a, {
"class": 'glass.Observable',
x: 12,
z: true
});
},
watchAll: function() {
var a, unwatch, watchArgs, watcher, _ref, _ref1;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch(watcher);
assert(watchArgs[0] === a);
assert(((_ref = watchArgs[1]) != null ? (_ref1 = _ref.watchers) != null ? _ref1[""] : void 0 : void 0) != null);
watchArgs.length = 0;
a.patch("a", "b", 3);
assertEquals(a.a, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
a: {
b: 3
}
});
unwatch();
assertEquals(a.watchers[""], {});
watchArgs.length = 0;
a.patch("a", "b", 3);
return assert(watchArgs.length === 0);
},
watchProperty: function() {
var a, unwatch, watchArgs, watcher;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch("foo", watcher);
assert(watchArgs.length === 0);
a.patch("foo", "b", 3);
assertEquals(a.foo, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
b: 3
});
watchArgs.length = 0;
a.patch("a", "b", 3);
assert(watchArgs.length === 0);
unwatch();
watchArgs.length = 0;
a.patch("foo", "b", 4);
return assert(watchArgs.length === 0);
}
}
}
},
"runtime\\glass.coffee": {
source: "require:
\tString: true
# runtime type tests
isFunction: (object) -> object? and typeof object is 'function'
isString: (object) -> object?.constructor is String
isArray: (object) -> Array.isArray object
isBoolean: (object) -> object? and typeof object is 'boolean'
isNumber: (object) -> object? and typeof object is 'number'
isObject: (object) -> typeof object is 'object'
isPlainObject: (object) -> object?.constructor is Object
isPrototype: (object) -> object? and object is object.constructor.prototype
isDate: (object) -> object?.constructor is Date
isPrimitive: (object) -> isString(object) or isBoolean(object) or isNumber(object) or isDate(object)
isPrivate: (property) -> property?[0] is '_'
# generic utility functions
values: (object) -> (value for key, value of object)
# generic patch method, uses patch method built into object if present
patch: (target, pathAndPatch...) ->
patch = JSONMergePatch.create.apply null, pathAndPatch
if isFunction target?.patch
target.patch patch
else
glass.JSONMergePatch.apply target, patch
# testing assertions
_getStackLocationInfo: (e, depth) ->
line = e.stack?.split('
')[depth]
return null unless line?
match = /\\(([\\w\\W]*?):(\\d+):(\\d+)\\)/.exec line
return {
file: match[1]
line: parseInt match[2]
column: parseInt match[3]
}
_throwAssertionFailure: (message) ->
try
throw new Error \"Assertion failed: \" + message
catch e
info = _getStackLocationInfo e, 3
if info?
_dumpFile info.file, info.line - 2, info.line + 2, info.line
throw e
_dumpFile: (file, from=1, to, highlight) ->
fs = require 'fs'
return unless fs?
try
content = fs.readFileSync(file).toString()
catch e
content = \"Source not found: #{e}\"
console.log '------------------------------------------------'
console.log file
console.log '------------------------------------------------'
number = 1
if content?
lines = content.split /
|
/
to ?= lines.length
for line in lines
lineNumber = number++
if lineNumber >= from and lineNumber <= to
num = String lineNumber
while num.length < 3
num += ' '
if lineNumber is highlight
`console.log(\"\\033[91m\" + num + \": \" + line + \"\\033[0m\");`
else
`console.log(num + \": \" + line);`
console.log '------------------------------------------------'
assert: (a) ->
_throwAssertionFailure JSON.stringify(a) unless a
assertTrue: (a) ->
_throwAssertionFailure JSON.stringify(a) + \" != true\" unless a is true
assertEquals: (a, b) ->
if JSON.stringify(a) isnt JSON.stringify(b)
_throwAssertionFailure JSON.stringify(a) + ' != ' + JSON.stringify(b)
# gets a unique string identifier for any object
getId:
do: ->
counter = 0
(a) ->
if a is null
return '__null__'
if a is undefined
return '__undefined__'
if typeof a is 'object' or typeof a is 'function'
return a.id ?= '__' + (counter++) + '__'
# 12 == \"12\" under this technique
return a.toString()
getType: (path) ->
array = if isArray path then path else path.split '.'
value = global
for step in path when value?
value = value[step]
throw new Error \"Type not found: #{path}\" unless isFunction value
value
test:
values: ->
assertEquals values({a:1,b:3,c:2}), [1,3,2]
patch: ->
x = {a:{foo:1,bar:3},b:2}
patch x, 'a', 'foo', 5
assertEquals x.a.foo, 5
",
input: "runtime\\glass.coffee",
content: {
require: {
String: true
},
isFunction: function(object) {
return (object != null) && typeof object === 'function';
},
isString: function(object) {
return (object != null ? object.constructor: void 0) === String;
},
isArray: function(object) {
return Array.isArray(object);
},
isBoolean: function(object) {
return (object != null) && typeof object === 'boolean';
},
isNumber: function(object) {
return (object != null) && typeof object === 'number';
},
isObject: function(object) {
return typeof object === 'object';
},
isPlainObject: function(object) {
return (object != null ? object.constructor: void 0) === Object;
},
isPrototype: function(object) {
return (object != null) && object === object.constructor.prototype;
},
isDate: function(object) {
return (object != null ? object.constructor: void 0) === Date;
},
isPrimitive: function(object) {
return isString(object) || isBoolean(object) || isNumber(object) || isDate(object);
},
isPrivate: function(property) {
return (property != null ? property[0] : void 0) === '_';
},
values: function(object) {
var key, value, _results;
_results = [];
for (key in object) {
value = object[key];
_results.push(value);
}
return _results;
},
patch: function() {
var patch, pathAndPatch, target;
target = arguments[0],
pathAndPatch = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
patch = JSONMergePatch.create.apply(null, pathAndPatch);
if (isFunction(target != null ? target.patch: void 0)) {
return target.patch(patch);
} else {
return glass.JSONMergePatch.apply(target, patch);
}
},
assert: function(a) {
if (!a) {
return _throwAssertionFailure(JSON.stringify(a));
}
},
assertTrue: function(a) {
if (a !== true) {
return _throwAssertionFailure(JSON.stringify(a) + " != true");
}
},
assertEquals: function(a, b) {
if (JSON.stringify(a) !== JSON.stringify(b)) {
return _throwAssertionFailure(JSON.stringify(a) + ' != ' + JSON.stringify(b));
}
},
getId: {
do: function() {
var counter;
counter = 0;
return function(a) {
var _ref;
if (a === null) {
return '__null__';
}
if (a === void 0) {
return '__undefined__';
}
if (typeof a === 'object' || typeof a === 'function') {
return (_ref = a.id) != null ? _ref: a.id = '__' + (counter++) + '__';
}
return a.toString();
};
}
},
getType: function(path) {
var array, step, value, _i, _len;
array = isArray(path) ? path: path.split('.');
value = global;
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
if (!isFunction(value)) {
throw new Error("Type not found: " + path);
}
return value;
},
test: {
values: function() {
return assertEquals(values({
a: 1,
b: 3,
c: 2
}), [1, 3, 2]);
},
patch: function() {
var x;
x = {
a: {
foo: 1,
bar: 3
},
b: 2
};
patch(x, 'a', 'foo', 5);
return assertEquals(x.a.foo, 5);
}
}
}
},
"runtime\\String.coffee": {
source: "extension: true
properties:
\tstartsWith: (s) -> @slice(0,s.length) is s
\tendsWith: (s) -> @slice(-s.length) is s
\tcontains: (s) -> @indexOf(s) >= 0
\ttoArray: () -> @split ''",
input: "runtime\\String.coffee",
content: {
extension: true,
properties: {
startsWith: function(s) {
return this.slice(0, s.length) === s;
},
endsWith: function(s) {
return this.slice( - s.length) === s;
},
contains: function(s) {
return this.indexOf(s) >= 0;
},
toArray: function() {
return this.split('');
}
}
}
}
}
} | {
options: {
input: {
dir: "runtime",
match: /\.(coffee|pegjs)$/
},
output: {
dir: "www/js"
},
script: {
includes: "www/includes.html",
prefix: "/js/"
},
module: {
main: "glass.js",
prefix: "./www/js/"
},
debug: "buildlog.html",
test: "glass.allTests",
addon: {
pregenerate: {
addUri: function(schema) {
var content, type, typeName, _ref2, _ref3;
_ref2 = schema.types;
for (typeName in _ref2) {
type = _ref2[typeName];
content = type.content;
if (content.extension) {
continue;
}
if ((_ref3 = content.uri) == null) {
content.uri = "global:/" + (content.path.replace(/\./g, '/'));
}
}
return schema;
}
}
},
namespace: ""
},
types: {
"runtime\\glass\\Component.coffee": {
source: "extends: 'Observable'
constructor: (properties) ->
@patch properties
# now site ourselves on our parent
if @parent
id = getId @
patch @parent, id, @
@
properties:
id:
description: 'string which uniquely identifies this component within its parent'
type: 'string'
parent:
description: 'the object that contains this component'
serializable: false
type: 'object'
disposed: false
dispose: -> @patch 'disposed', true
notify: (change) ->
Observable.prototype.notify.apply this, arguments
if change?.disposed
# dispose of any disposable children
for id, child of @ when child?.parent is @
child.dispose?()
# remove self from parent
if @id and @parent
patch @parent, @id, undefined
return
test:
lifecycle: ->
parent = new Component
assert not parent.id?
assert not parent.parent?
child = new Component parent:parent
# id should be automatically assigned
assert isString child.id
assert parent is child.parent
assert parent[child.id] is child
assert parent.hasOwnProperty child.id
parent.dispose()
assert child.disposed is true
assert not parent.hasOwnProperty child.id
nonEnumerability: ->
visibleKeys = (key for key of new Component)
assertEquals visibleKeys, []",
input: "runtime\\glass\\Component.coffee",
content: {
extends: "Observable",
constructor: function(properties) {
var id;
this.patch(properties);
if (this.parent) {
id = getId(this);
patch(this.parent, id, this);
}
return this;
},
properties: {
id: {
description: "string which uniquely identifies this component within its parent",
type: "string"
},
parent: {
description: "the object that contains this component",
serializable: false,
type: "object"
},
disposed: false,
dispose: function() {
return this.patch('disposed', true);
},
notify: function(change) {
var child, id;
Observable.prototype.notify.apply(this, arguments);
if (change != null ? change.disposed: void 0) {
for (id in this) {
child = this[id];
if ((child != null ? child.parent: void 0) === this) {
if (typeof child.dispose === "function") {
child.dispose();
}
}
}
if (this.id && this.parent) {
patch(this.parent, this.id, void 0);
}
}
}
},
test: {
lifecycle: function() {
var child, parent;
parent = new Component;
assert(!(parent.id != null));
assert(!(parent.parent != null));
child = new Component({
parent: parent
});
assert(isString(child.id));
assert(parent === child.parent);
assert(parent[child.id] === child);
assert(parent.hasOwnProperty(child.id));
parent.dispose();
assert(child.disposed === true);
return assert(!parent.hasOwnProperty(child.id));
},
nonEnumerability: function() {
var key, visibleKeys;
visibleKeys = (function() {
var _results;
_results = [];
for (key in new Component) {
_results.push(key);
}
return _results;
})();
return assertEquals(visibleKeys, []);
}
}
}
},
"runtime\\glass\\Container.coffee": {
source: "extends: 'Observable'
properties:
watch: ->
unwatch: ->
",
input: "runtime\\glass\\Container.coffee",
content: {
extends: "Observable",
properties: {
watch: function() {},
unwatch: function() {}
}
}
},
"runtime\\glass\\Expression\\_parser.pegjs": {
source: "{
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e,array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++)
array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
}
start = expression
expression = conditional
conditional = e:or args:(\"?\" b:expression \":\" c:expression {return [b,c];})* {
while (args.length > 0) {
e = expr(\"?:\", [e].concat(args.pop()));
}
return e;
}
or = a:and b:((\"or\") and)* { return joinLeft(a,b); }
and = a:equality b:((\"and\") equality)* { return joinLeft(a,b); }
equality = a:rel b:((\"==\" / \"!=\") rel)* { return joinLeft(a,b); }
rel = a:sum b:((\"<=\" / \">=\" / \"<\" / \">\") sum)* { return joinLeft(a,b); }
sum = a:product b:((\"+\" / \"-\") product)* { return joinLeft(a,b); }
product = a:not b:((\"*\" / \"div\" / \"mod\") not)* { return joinLeft(a,b); }
not = ops:(s op:(\"!\" / \"~\" / \"+\" / \"-\") { return op; })* b:primary { return unaryRight(ops,b); }
primary = s a:(group / literal / path) s { return a; }
group = \"(\" a:expression \")\" { return a; }
literal = s a:(boolean / number / string / array / object) s { return a; }
boolean = a:(\"true\" / \"false\") { return a == \"true\"; }
number = a:([0-9]+ (\".\" [0-9]+)?) { return parseFloat(toString(a)); }
hex = [a-fA-F0-9]
// as per JSON http://www.json.org
string = a:( '\"' (
[\\u0000-\\u0021\\u0023-\\u005c\\u005e-\\uffff] // all unicode chars except \\ and \"
/ (\"\\\\\" (\"\\\"\" / \"\\\\\" / \"\\/\" / \"b\" / \"f\" / \"n\" / \"r\" / \"t\" / (\"u\" hex hex hex hex)))
)* '\"' )
{ return JSON.parse(toString(a)); }
array = \"[\" a:values \"]\" { return expr(\"array\", a); }
values = first:expression? args:(\",\" b:expression {return b;})* {
if (first != \"\") { args.unshift(first); } return args;
}
object = \"{\" a:keyvalues \"}\" { return expr(\"object\", a); }
keyvalue = s a:string s \":\" b:expression { return [a,b]; }
keyvalues = first:keyvalue? rest:(\",\" b:keyvalue {return b;})* {
if (first) { rest.unshift(first); } return rest;
}
ref = a:(\"//\" / \"/\" / \"$\" / \"**\" / \"*\" / \"..\" / \".\") b:slashProperty? {
e = expr(a); if (b) { b.args.unshift(e); e = b; } return e;
}
/ a:id { return expr(\"ref\", [a]); }
id = a:[a-z_]+ b:[a-z_0-9]* { return a.join('') + b.join(''); }
property = \"/\" a:slashProperty { return a; }
/ \"{\" a:expression \"}\" { return expr(\"{}\", [a]); } // locally scoped expression
/ \"[\" a:expression \"]\" { return expr(\"[]\", [a]); } // predicate
slashProperty = a:(id/number/string) { return expr(\"/\", [a]); }
/ a:(\"..\" / \"*\") { return expr(a, []); }
s \"space\" = [ ]* { return ''; }
path = a:root b:step* {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
}
root = a:implicitDotRoot b:dotStep? { return joinPath(a,b); }
/ explicitDotRoot
step = \".\" a:dotStep { return a; }
/ noDotStep
implicitDotRoot = \"/\" { return expr(\"root\"); }
/ \"@\" { return expr(\"this\"); }
/ \".\" a:\".\"+ { return expr(\"ancestor\", [a.length]); }
explicitDotRoot = a:id { return expr(\"ref\", [a]); }
/ \"*\" { return expr(\"values\", []); }
dotStep = a:(id / string / number) { return expr(\"get\", [a]); }
/ \"*\" { return expr(\"values\", []); }
noDotStep = \"{\" a:expression \"}\" { return expr(\"eval\", [a]); }
/ \"[\" a:expression \"]\" { return expr(\"pred\", [a]); }
/ \"(\" a:values \")\" { return expr(\"call\", [a]); }
",
input: "runtime\\glass\\Expression\\_parser.pegjs",
content: {
value: {
parse: function(input, startRule) {
var parseFunctions = {
"conditional": parse_conditional,
"or": parse_or,
"and": parse_and,
"equality": parse_equality,
"rel": parse_rel,
"sum": parse_sum,
"product": parse_product,
"not": parse_not,
"primary": parse_primary,
"group": parse_group,
"literal": parse_literal,
"boolean": parse_boolean,
"number": parse_number,
"hex": parse_hex,
"string": parse_string,
"array": parse_array,
"values": parse_values,
"object": parse_object,
"keyvalue": parse_keyvalue,
"keyvalues": parse_keyvalues,
"ref": parse_ref,
"id": parse_id,
"property": parse_property,
"slashProperty": parse_slashProperty,
"s": parse_s,
"path": parse_path,
"root": parse_root,
"step": parse_step,
"implicitDotRoot": parse_implicitDotRoot,
"explicitDotRoot": parse_explicitDotRoot,
"dotStep": parse_dotStep,
"noDotStep": parse_noDotStep
};
if (startRule !== undefined) {
if (parseFunctions[startRule] === undefined) {
throw new Error("Invalid rule name: " + quote(startRule) + ".");
}
} else {
startRule = "conditional";
}
var pos = 0;
var reportFailures = 0;
var rightmostFailuresPos = 0;
var rightmostFailuresExpected = [];
function padLeft(input, padding, length) {
var result = input;
var padLength = length - input.length;
for (var i = 0; i < padLength; i++) {
result = padding + result;
}
return result;
}
function escape(ch) {
var charCode = ch.charCodeAt(0);
var escapeChar;
var length;
if (charCode <= 0xFF) {
escapeChar = 'x';
length = 2;
} else {
escapeChar = 'u';
length = 4;
}
return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
}
function matchFailed(failure) {
if (pos < rightmostFailuresPos) {
return;
}
if (pos > rightmostFailuresPos) {
rightmostFailuresPos = pos;
rightmostFailuresExpected = [];
}
rightmostFailuresExpected.push(failure);
}
function parse_conditional() {
var result0, result1, result2, result3, result4, result5;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_or();
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, e, args) {
while (args.length > 0) {
e = expr("?:", [e].concat(args.pop()));
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_or() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_and();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_and() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_equality();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_equality() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_rel();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_rel() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_sum();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_sum() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_product();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_product() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_not();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_not() {
var result0, result1, result2;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = [];
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
while (result1 !== null) {
result0.push(result1);
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
}
if (result0 !== null) {
result1 = parse_primary();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, ops, b) {
return unaryRight(ops, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_primary() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_group();
if (result1 === null) {
result1 = parse_literal();
if (result1 === null) {
result1 = parse_path();
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_group() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_literal() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_boolean();
if (result1 === null) {
result1 = parse_number();
if (result1 === null) {
result1 = parse_string();
if (result1 === null) {
result1 = parse_array();
if (result1 === null) {
result1 = parse_object();
}
}
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_boolean() {
var result0;
var pos0;
pos0 = pos;
if (input.substr(pos, 4) === "true") {
result0 = "true";
pos += 4;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"true\"");
}
}
if (result0 === null) {
if (input.substr(pos, 5) === "false") {
result0 = "false";
pos += 5;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"false\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a == "true";
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_number() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
pos2 = pos;
if (input.charCodeAt(pos) === 46) {
result1 = ".";
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result1 !== null) {
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result3 !== null) {
result2 = [];
while (result3 !== null) {
result2.push(result3);
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result2 = null;
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos2;
}
} else {
result1 = null;
pos = pos2;
}
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return parseFloat(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_hex() {
var result0;
if (/^[a-fA-F0-9]/.test(input.charAt(pos))) {
result0 = input.charAt(pos);
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("[a-fA-F0-9]");
}
}
return result0;
}
function parse_string() {
var result0, result1, result2, result3, result4, result5, result6, result7;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 34) {
result0 = "\"";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result0 !== null) {
result1 = [];
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
}
if (result1 !== null) {
if (input.charCodeAt(pos) === 34) {
result2 = "\"";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return JSON.parse(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_array() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("array", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_values() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_conditional();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, args) {
if (first != "") {
args.unshift(first);
}
return args;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_object() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_keyvalues();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("object", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalue() {
var result0, result1, result2, result3, result4;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_string();
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
if (input.charCodeAt(pos) === 58) {
result3 = ":";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result3 !== null) {
result4 = parse_conditional();
if (result4 !== null) {
result0 = [result0, result1, result2, result3, result4];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return [a, b];
})(pos0, result0[1], result0[4]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalues() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_keyvalue();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, rest) {
if (first) {
rest.unshift(first);
}
return rest;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_ref() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.substr(pos, 2) === "//") {
result0 = "//";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"//\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 36) {
result0 = "$";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"$\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "**") {
result0 = "**";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"**\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
}
}
}
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
e = expr(a);
if (b) {
b.args.unshift(e);
e = b;
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_id() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
result1 = [];
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return a.join('') + b.join('');
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_property() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("{}", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("[]", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_slashProperty() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_number();
if (result0 === null) {
result0 = parse_string();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("/", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(a, []);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_s() {
var result0, result1;
var pos0;
reportFailures++;
pos0 = pos;
result0 = [];
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
while (result1 !== null) {
result0.push(result1);
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
}
if (result0 !== null) {
result0 = (function(offset) {
return '';
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
reportFailures--;
if (reportFailures === 0 && result0 === null) {
matchFailed("space");
}
return result0;
}
function parse_path() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_root();
if (result0 !== null) {
result1 = [];
result2 = parse_step();
while (result2 !== null) {
result1.push(result2);
result2 = parse_step();
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_root() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_implicitDotRoot();
if (result0 !== null) {
result1 = parse_dotStep();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinPath(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_explicitDotRoot();
}
return result0;
}
function parse_step() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
result1 = parse_dotStep();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_noDotStep();
}
return result0;
}
function parse_implicitDotRoot() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("root");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 64) {
result0 = "@";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"@\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("this");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result2 !== null) {
result1 = [];
while (result2 !== null) {
result1.push(result2);
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
} else {
result1 = null;
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ancestor", [a.length]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_explicitDotRoot() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_dotStep() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_string();
if (result0 === null) {
result0 = parse_number();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("get", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_noDotStep() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("eval", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("pred", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("call", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function cleanupExpected(expected) {
expected.sort();
var lastExpected = null;
var cleanExpected = [];
for (var i = 0; i < expected.length; i++) {
if (expected[i] !== lastExpected) {
cleanExpected.push(expected[i]);
lastExpected = expected[i];
}
}
return cleanExpected;
}
function computeErrorPosition() {
/*
* The first idea was to use |String.split| to break the input up to the
* error position along newlines and derive the line and column from
* there. However IE's |split| implementation is so broken that it was
* enough to prevent it.
*/
var line = 1;
var column = 1;
var seenCR = false;
for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
var ch = input.charAt(i);
if (ch === "
") {
if (!seenCR) {
line++;
}
column = 1;
seenCR = false;
} else if (ch === "
" || ch === "\u2028" || ch === "\u2029") {
line++;
column = 1;
seenCR = true;
} else {
column++;
seenCR = false;
}
}
return {
line: line,
column: column
};
}
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e, array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++) array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
var result = parseFunctions[startRule]();
/*
* The parser is now in one of the following three states:
*
* 1. The parser successfully parsed the whole input.
*
* - |result !== null|
* - |pos === input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 2. The parser successfully parsed only a part of the input.
*
* - |result !== null|
* - |pos < input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 3. The parser did not successfully parse any part of the input.
*
* - |result === null|
* - |pos === 0|
* - |rightmostFailuresExpected| contains at least one failure
*
* All code following this comment (including called functions) must
* handle these states.
*/
if (result === null || pos !== input.length) {
var offset = Math.max(pos, rightmostFailuresPos);
var found = offset < input.length ? input.charAt(offset) : null;
var errorPosition = computeErrorPosition();
throw new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column);
}
return result;
},
toSource: function() {
return this._source;
},
SyntaxError: function(expected, found, offset, line, column) {
function buildMessage(expected, found) {
var expectedHumanized, foundHumanized;
switch (expected.length) {
case 0:
expectedHumanized = "end of input";
break;
case 1:
expectedHumanized = expected[0];
break;
default:
expectedHumanized = expected.slice(0, expected.length - 1).join(", ") + " or " + expected[expected.length - 1];
}
foundHumanized = found ? quote(found) : "end of input";
return "Expected " + expectedHumanized + " but " + foundHumanized + " found.";
}
this.name = "SyntaxError";
this.expected = expected;
this.found = found;
this.message = buildMessage(expected, found);
this.offset = offset;
this.line = line;
this.column = column;
}
}
}
},
"runtime\\glass\\Expression.coffee": {
source: "constructor: (op, args) ->
@op = op
@args = args if args?
@
properties:
op:
type: 'string'
args:
type: 'array'
test: ->
return
peg = require 'pegjs'
fs = require 'fs'
parserSource = fs.readFileSync 'runtime/glass/Expression/_parser.pegjs', 'utf8'
parser = peg.buildParser parserSource
tests =
\"a.b.c\": {op:\"get\",args:[{op:\"get\",args:[{op:\"ref\",args:[\"a\"]},\"b\"]},\"c\"]}
\"a.1\": {op:\"get\",args:[{op:\"ref\",args:[\"a\"]},1]}
\"true\": true
\"false\": false
\"45.8\": 45.8
\"(45.8)\": 45.8
\"((45.8))\": 45.8
\"alpha\": {op:\"ref\",args:[\"alpha\"]}
\"35 + true * 2\": {op:\"+\", args:[35, {op:\"*\", args:[true,2]}]}
\" 5 * ( 2 + 2 ) \": {op:\"*\", args:[5, {op:\"+\", args:[2,2]}]}
\" ! ! true\": {op:\"!\",args:[{op:\"!\",args:[true]}]}
\"5 + -x\": {op:\"+\",args:[5,{op:\"-\",args:[{op:\"ref\",args:[\"x\"]}]}]}
\"true == 5 >= 2\": {op:\"==\",args:[true,{op:\">=\",args:[5,2]}]}
\"1 or 2 and 3\": {op:\"or\",args:[1,{op:\"and\",args:[2,3]}]}
\"1 ? 2 : 3\": {op:\"?:\",args:[1,2,3]}
\"1 ? 2 : 3 ? 4 : 5\" : {op:\"?:\",args:[1,2,{op:\"?:\",args:[3,4,5]}]}
\"a()(1,2)\" : {op:\"call\",args:[{op:\"call\",args:[{op:\"ref\",args:[\"a\"]},[]]},[1,2]]}
\"@\" : {op:\"this\"}
\"@foo\" : {op:\"get\",args:[{op:\"this\"},\"foo\"]}
'\"hello\"': \"hello\"
'\"\\\\t\\
\\
\\\\b\\\\\\\\foo\\\\\\/\"' : \"\\t
\\b\\\\foo\\/\"
\"[]\": {op:\"array\",args:[]}
\"[1,2]\": {op:\"array\",args:[1,2]}
\"[1+2]\": {op:\"array\",args:[{op:\"+\",args:[1,2]}]}
\"{}\": {op:\"object\",args:[]}
'{\"a\":2}': {op:\"object\",args:[[\"a\",2]]}
'{\"a\":2,\"b\":1+2}': {op:\"object\",args:[[\"a\",2],[\"b\",{op:\"+\",args:[1,2]}]]}
'@\"alpha\"': {op:\"get\",args:[{op:\"this\"},\"alpha\"]}
'*': {op:\"values\",args:[]}
'*.*': {op:\"values\",args:[{op:\"values\",args:[]}]}
\"foo.*\": {op:\"values\",args:[{op:\"ref\",args:[\"foo\"]}]}
\"..\": {op:\"ancestor\",args:[1]}
\"...\": {op:\"ancestor\",args:[2]}
\"@*{1+2}\": {op:\"eval\",args:[{op:\"values\",args:[{op:\"this\"}]},{op:\"+\",args:[1,2]}]}
\"/\": {op:\"root\"}
\"/foo\": {op:\"get\",args:[{op:\"root\"},\"foo\"]}
\"/*\": {op:\"values\",args:[{op:\"root\"}]}
for text, expected of tests
result = parser.parse text
if JSON.stringify(result) is JSON.stringify(expected)
console.log 'Pass: ' + text
else
console.log text, JSON.stringify result
return
",
input: "runtime\\glass\\Expression.coffee",
content: {
constructor: function(op, args) {
this.op = op;
if (args != null) {
this.args = args;
}
return this;
},
properties: {
op: {
type: "string"
},
args: {
type: "array"
}
},
test: function() {
var expected, fs, parser, parserSource, peg, result, tests, text;
return;
peg = require('pegjs');
fs = require('fs');
parserSource = fs.readFileSync('runtime/glass/Expression/_parser.pegjs', 'utf8');
parser = peg.buildParser(parserSource);
tests = {
"a.b.c": {
op: "get",
args: [{
op: "get",
args: [{
op: "ref",
args: ["a"]
},
"b"]
},
"c"]
},
"a.1": {
op: "get",
args: [{
op: "ref",
args: ["a"]
},
1]
},
"true": true,
"false": false,
"45.8": 45.8,
"(45.8)": 45.8,
"((45.8))": 45.8,
"alpha": {
op: "ref",
args: ["alpha"]
},
"35 + true * 2": {
op: "+",
args: [35, {
op: "*",
args: [true, 2]
}]
},
" 5 * ( 2 + 2 ) ": {
op: "*",
args: [5, {
op: "+",
args: [2, 2]
}]
},
" ! ! true": {
op: "!",
args: [{
op: "!",
args: [true]
}]
},
"5 + -x": {
op: "+",
args: [5, {
op: "-",
args: [{
op: "ref",
args: ["x"]
}]
}]
},
"true == 5 >= 2": {
op: "==",
args: [true, {
op: ">=",
args: [5, 2]
}]
},
"1 or 2 and 3": {
op: "or",
args: [1, {
op: "and",
args: [2, 3]
}]
},
"1 ? 2 : 3": {
op: "?:",
args: [1, 2, 3]
},
"1 ? 2 : 3 ? 4 : 5": {
op: "?:",
args: [1, 2, {
op: "?:",
args: [3, 4, 5]
}]
},
"a()(1,2)": {
op: "call",
args: [{
op: "call",
args: [{
op: "ref",
args: ["a"]
},
[]]
},
[1, 2]]
},
"@": {
op: "this"
},
"@foo": {
op: "get",
args: [{
op: "this"
},
"foo"]
},
'"hello"': "hello",
'"\\t
\\b\\\\foo\\\/"': "\t
\b\\foo\/",
"[]": {
op: "array",
args: []
},
"[1,2]": {
op: "array",
args: [1, 2]
},
"[1+2]": {
op: "array",
args: [{
op: "+",
args: [1, 2]
}]
},
"{}": {
op: "object",
args: []
},
'{"a":2}': {
op: "object",
args: [["a", 2]]
},
'{"a":2,"b":1+2}': {
op: "object",
args: [["a", 2], ["b", {
op: "+",
args: [1, 2]
}]]
},
'@"alpha"': {
op: "get",
args: [{
op: "this"
},
"alpha"]
},
'*': {
op: "values",
args: []
},
'*.*': {
op: "values",
args: [{
op: "values",
args: []
}]
},
"foo.*": {
op: "values",
args: [{
op: "ref",
args: ["foo"]
}]
},
"..": {
op: "ancestor",
args: [1]
},
"...": {
op: "ancestor",
args: [2]
},
"@*{1+2}": {
op: "eval",
args: [{
op: "values",
args: [{
op: "this"
}]
},
{
op: "+",
args: [1, 2]
}]
},
"/": {
op: "root"
},
"/foo": {
op: "get",
args: [{
op: "root"
},
"foo"]
},
"/*": {
op: "values",
args: [{
op: "root"
}]
}
};
for (text in tests) {
expected = tests[text];
result = parser.parse(text);
if (JSON.stringify(result) === JSON.stringify(expected)) {
console.log('Pass: ' + text);
} else {
console.log(text, JSON.stringify(result));
}
}
}
}
},
"runtime\\glass\\JSONMergePatch.coffee": {
source: "
# applies a patch to the target object and returns the resulting target
apply: (target, patch) ->
if target? and target isnt patch and isPlainObject(patch) and not isPrimitive(target)
for key, value of patch
if value is undefined
delete target[key]
else
target[key] = apply target[key], patch[key]
return target
else
return patch
# (path1, path2, path3.., patch) ->
create: ->
if arguments.length is 1
return arguments[0]
result = {}
current = result
for arg, i in arguments when i + 1 < arguments.length
last = i + 2 is arguments.length
current = current[arg] = if last then arguments[arguments.length-1] else {}
result
test: ->
assertEquals {a:{b:12}}, create 'a', 'b', 12
assertEquals {a:3}, apply({a:1,b:2}, {a:3,b:undefined})
",
input: "runtime\\glass\\JSONMergePatch.coffee",
content: {
apply: function(target, patch) {
var key, value;
if ((target != null) && target !== patch && isPlainObject(patch) && !isPrimitive(target)) {
for (key in patch) {
value = patch[key];
if (value === void 0) {
delete target[key];
} else {
target[key] = apply(target[key], patch[key]);
}
}
return target;
} else {
return patch;
}
},
create: function() {
var arg, current, i, last, result, _i, _len;
if (arguments.length === 1) {
return arguments[0];
}
result = {};
current = result;
for (i = _i = 0, _len = arguments.length; _i < _len; i = ++_i) {
arg = arguments[i];
if (! (i + 1 < arguments.length)) {
continue;
}
last = i + 2 === arguments.length;
current = current[arg] = last ? arguments[arguments.length - 1] : {};
}
return result;
},
test: function() {
assertEquals({
a: {
b: 12
}
},
create('a', 'b', 12));
return assertEquals({
a: 3
},
apply({
a: 1,
b: 2
},
{
a: 3,
b: void 0
}));
}
}
},
"runtime\\glass\\JSONPointer.coffee": {
source: "# json pointer implementation as per
# http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-05
_decodeStep: (step) -> step.replace(/~1/g, '/').replace(/~0/g, '~')
_getLastStep: (pointer) ->
_decodeStep pointer.substring(pointer.lastIndexOf('/') + 1)
_getParent: (pointer) ->
if not pointer?.length
null
else
pointer.substring(0, pointer.lastIndexOf('/'))
toArray: (pointer) ->
for step in pointer.substring(1).split('/')
_decodeStep step
get: (doc, pointer) ->
value = doc
if pointer.length
path = toArray pointer
for step in path when value?
value = value[step]
value
set: (doc, pointer, value) ->
parentPointer = _getParent pointer
if parentPointer?
parent = get doc, parentPointer
lastStep = _getLastStep pointer
parent[lastStep] = value
value
test: ->
assertEquals _getParent(\"/a/b/c\"), \"/a/b\"
assertEquals _getParent(\"/a\"), \"\"
assertEquals _getParent(\"\"), null
assertEquals _getLastStep(\"/a/b/c\"), \"c\"
assertEquals _getLastStep(\"/a~0~1\"), \"a~/\"
assertEquals _getLastStep(\"\"), \"\"
# tests as per spec
doc = {
\"foo\": [\"bar\", \"baz\"],
\"\": 0,
\"a/b\": 1,
\"c%d\": 2,
\"e^f\": 3,
\"g|h\": 4,
\"i\\\\j\": 5,
\"k\\\"l\": 6,
\" \": 7,
\"m~n\": 8
}
assertEquals get(doc, \"\"), doc
assertEquals get(doc, \"/foo\"), [\"bar\", \"baz\"]
assertEquals get(doc, \"/foo/0\"), \"bar\"
assertEquals get(doc, \"/\"), 0
assertEquals get(doc, \"/a~1b\"), 1
assertEquals get(doc, \"/c%d\"), 2
assertEquals get(doc, \"/e^f\"), 3
assertEquals get(doc, \"/g|h\"), 4
assertEquals get(doc, \"/i\\\\j\"), 5
assertEquals get(doc, \"/k\\\"l\"), 6
assertEquals get(doc, \"/ \"), 7
assertEquals get(doc, \"/m~0n\"), 8
# now test set
assertEquals set(doc, \"/\", 10), 10
assertEquals doc[\"\"], 10
assertEquals set(doc, \"/foo/0\", 10), 10
assertEquals doc.foo[0], 10",
input: "runtime\\glass\\JSONPointer.coffee",
content: {
toArray: function(pointer) {
var step, _i, _len, _ref, _results;
_ref = pointer.substring(1).split('/');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
step = _ref[_i];
_results.push(_decodeStep(step));
}
return _results;
},
get: function(doc, pointer) {
var path, step, value, _i, _len;
value = doc;
if (pointer.length) {
path = toArray(pointer);
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
}
return value;
},
set: function(doc, pointer, value) {
var lastStep, parent, parentPointer;
parentPointer = _getParent(pointer);
if (parentPointer != null) {
parent = get(doc, parentPointer);
lastStep = _getLastStep(pointer);
parent[lastStep] = value;
}
return value;
},
test: function() {
var doc;
assertEquals(_getParent("/a/b/c"), "/a/b");
assertEquals(_getParent("/a"), "");
assertEquals(_getParent(""), null);
assertEquals(_getLastStep("/a/b/c"), "c");
assertEquals(_getLastStep("/a~0~1"), "a~/");
assertEquals(_getLastStep(""), "");
doc = {
"foo": ["bar", "baz"],
"": 0,
"a/b": 1,
"c%d": 2,
"e^f": 3,
"g|h": 4,
"i\\j": 5,
"k\"l": 6,
" ": 7,
"m~n": 8
};
assertEquals(get(doc, ""), doc);
assertEquals(get(doc, "/foo"), ["bar", "baz"]);
assertEquals(get(doc, "/foo/0"), "bar");
assertEquals(get(doc, "/"), 0);
assertEquals(get(doc, "/a~1b"), 1);
assertEquals(get(doc, "/c%d"), 2);
assertEquals(get(doc, "/e^f"), 3);
assertEquals(get(doc, "/g|h"), 4);
assertEquals(get(doc, "/i\\j"), 5);
assertEquals(get(doc, "/k\"l"), 6);
assertEquals(get(doc, "/ "), 7);
assertEquals(get(doc, "/m~0n"), 8);
assertEquals(set(doc, "/", 10), 10);
assertEquals(doc[""], 10);
assertEquals(set(doc, "/foo/0", 10), 10);
return assertEquals(doc.foo[0], 10);
}
}
},
"runtime\\glass\\Observable.coffee": {
source: "properties:
is: (type) -> @constructor.implements[type.path ? type] is true
watchers:
serializable: false
watch: (property, watcher) ->
if isFunction property
watcher = property
property = ''
id = getId watcher
@patch 'watchers', property, id, watcher
# returns a function which will remove the watch
=> @patch 'watchers', property, getId(watcher), undefined
patch: (change) ->
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
try
JSONMergePatch.apply this, change
catch e
console.log e
finally
@notify change
return
notify: (change) ->
if @watchers?
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
for property, watchers of @watchers
if property.length is 0 or change.hasOwnProperty property
changeArg = if property.length is 0 then change else change[property]
for id, watcher of watchers
watcher this, changeArg
return
toJSON: ->
values =
class: @constructor.path
# serialize statically defined properties
for name, property of @constructor.properties
value = @[name]
if property.serializable isnt false and not isFunction(value)
values[name] = value
# serialize custom properties if allowed by schema
if @constructor.additionalProperties isnt false
for own name, value of @ when not isPrivate name
values[name] = value
values
toString: -> @toJSON()
test:
toJSON: ->
# I need this test later
# on a class that actually has serializable properties
a = new Observable
a.x = 12
a.y = ->
a.z = true
assertEquals a, {class:'glass.Observable', x:12,z:true}
watchAll: ->
# we should actually be able to watch ourselves get added to watchers
# this is very meta.
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch watcher
# now make sure we were called with our own watcher
assert watchArgs[0] is a
assert watchArgs[1]?.watchers?[\"\"]?
# reset watchArgs, and watch something else
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assertEquals a.a, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {a:{b:3}}
# now unwatch
unwatch()
# make sure universal watcher is now empty
assertEquals a.watchers[\"\"], {}
# now reset and do a new event, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
watchProperty: ->
# watch a property
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch \"foo\", watcher
# now make sure we were not called
assert watchArgs.length is 0
# reset watchArgs, and watch something else
a.patch \"foo\", \"b\", 3
assertEquals a.foo, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {b:3}
# now reset and do a different property, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
# now unwatch
unwatch()
# make sure we no longer see foo
watchArgs.length = 0
a.patch \"foo\", \"b\", 4
assert watchArgs.length is 0
",
input: "runtime\\glass\\Observable.coffee",
content: {
properties: {
is: function(type) {
var _ref;
return this.constructor["implements"][(_ref = type.path) != null ? _ref: type] === true;
},
watchers: {
serializable: false
},
watch: function(property, watcher) {
var id, _this = this;
if (isFunction(property)) {
watcher = property;
property = '';
}
id = getId(watcher);
this.patch('watchers', property, id, watcher);
return function() {
return _this.patch('watchers', property, getId(watcher), void 0);
};
},
patch: function(change) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
try {
JSONMergePatch.apply(this, change);
} catch(e) {
console.log(e);
} finally {
this.notify(change);
}
},
notify: function(change) {
var changeArg, id, property, watcher, watchers, _ref;
if (this.watchers != null) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
_ref = this.watchers;
for (property in _ref) {
watchers = _ref[property];
if (property.length === 0 || change.hasOwnProperty(property)) {
changeArg = property.length === 0 ? change: change[property];
for (id in watchers) {
watcher = watchers[id];
watcher(this, changeArg);
}
}
}
}
},
toJSON: function() {
var name, property, value, values, _ref;
values = {
"class": this.constructor.path
};
_ref = this.constructor.properties;
for (name in _ref) {
property = _ref[name];
value = this[name];
if (property.serializable !== false && !isFunction(value)) {
values[name] = value;
}
}
if (this.constructor.additionalProperties !== false) {
for (name in this) {
if (!__hasProp.call(this, name)) continue;
value = this[name];
if (!isPrivate(name)) {
values[name] = value;
}
}
}
return values;
},
toString: function() {
return this.toJSON();
}
},
test: {
toJSON: function() {
var a;
a = new Observable;
a.x = 12;
a.y = function() {};
a.z = true;
return assertEquals(a, {
"class": 'glass.Observable',
x: 12,
z: true
});
},
watchAll: function() {
var a, unwatch, watchArgs, watcher, _ref, _ref1;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch(watcher);
assert(watchArgs[0] === a);
assert(((_ref = watchArgs[1]) != null ? (_ref1 = _ref.watchers) != null ? _ref1[""] : void 0 : void 0) != null);
watchArgs.length = 0;
a.patch("a", "b", 3);
assertEquals(a.a, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
a: {
b: 3
}
});
unwatch();
assertEquals(a.watchers[""], {});
watchArgs.length = 0;
a.patch("a", "b", 3);
return assert(watchArgs.length === 0);
},
watchProperty: function() {
var a, unwatch, watchArgs, watcher;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch("foo", watcher);
assert(watchArgs.length === 0);
a.patch("foo", "b", 3);
assertEquals(a.foo, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
b: 3
});
watchArgs.length = 0;
a.patch("a", "b", 3);
assert(watchArgs.length === 0);
unwatch();
watchArgs.length = 0;
a.patch("foo", "b", 4);
return assert(watchArgs.length === 0);
}
}
}
},
"runtime\\glass.coffee": {
source: "require:
\tString: true
# runtime type tests
isFunction: (object) -> object? and typeof object is 'function'
isString: (object) -> object?.constructor is String
isArray: (object) -> Array.isArray object
isBoolean: (object) -> object? and typeof object is 'boolean'
isNumber: (object) -> object? and typeof object is 'number'
isObject: (object) -> typeof object is 'object'
isPlainObject: (object) -> object?.constructor is Object
isPrototype: (object) -> object? and object is object.constructor.prototype
isDate: (object) -> object?.constructor is Date
isPrimitive: (object) -> isString(object) or isBoolean(object) or isNumber(object) or isDate(object)
isPrivate: (property) -> property?[0] is '_'
# generic utility functions
values: (object) -> (value for key, value of object)
# generic patch method, uses patch method built into object if present
patch: (target, pathAndPatch...) ->
patch = JSONMergePatch.create.apply null, pathAndPatch
if isFunction target?.patch
target.patch patch
else
glass.JSONMergePatch.apply target, patch
# testing assertions
_getStackLocationInfo: (e, depth) ->
line = e.stack?.split('
')[depth]
return null unless line?
match = /\\(([\\w\\W]*?):(\\d+):(\\d+)\\)/.exec line
return {
file: match[1]
line: parseInt match[2]
column: parseInt match[3]
}
_throwAssertionFailure: (message) ->
try
throw new Error \"Assertion failed: \" + message
catch e
info = _getStackLocationInfo e, 3
if info?
_dumpFile info.file, info.line - 2, info.line + 2, info.line
throw e
_dumpFile: (file, from=1, to, highlight) ->
fs = require 'fs'
return unless fs?
try
content = fs.readFileSync(file).toString()
catch e
content = \"Source not found: #{e}\"
console.log '------------------------------------------------'
console.log file
console.log '------------------------------------------------'
number = 1
if content?
lines = content.split /
|
/
to ?= lines.length
for line in lines
lineNumber = number++
if lineNumber >= from and lineNumber <= to
num = String lineNumber
while num.length < 3
num += ' '
if lineNumber is highlight
`console.log(\"\\033[91m\" + num + \": \" + line + \"\\033[0m\");`
else
`console.log(num + \": \" + line);`
console.log '------------------------------------------------'
assert: (a) ->
_throwAssertionFailure JSON.stringify(a) unless a
assertTrue: (a) ->
_throwAssertionFailure JSON.stringify(a) + \" != true\" unless a is true
assertEquals: (a, b) ->
if JSON.stringify(a) isnt JSON.stringify(b)
_throwAssertionFailure JSON.stringify(a) + ' != ' + JSON.stringify(b)
# gets a unique string identifier for any object
getId:
do: ->
counter = 0
(a) ->
if a is null
return '__null__'
if a is undefined
return '__undefined__'
if typeof a is 'object' or typeof a is 'function'
return a.id ?= '__' + (counter++) + '__'
# 12 == \"12\" under this technique
return a.toString()
getType: (path) ->
array = if isArray path then path else path.split '.'
value = global
for step in path when value?
value = value[step]
throw new Error \"Type not found: #{path}\" unless isFunction value
value
test:
values: ->
assertEquals values({a:1,b:3,c:2}), [1,3,2]
patch: ->
x = {a:{foo:1,bar:3},b:2}
patch x, 'a', 'foo', 5
assertEquals x.a.foo, 5
",
input: "runtime\\glass.coffee",
content: {
require: {
String: true
},
isFunction: function(object) {
return (object != null) && typeof object === 'function';
},
isString: function(object) {
return (object != null ? object.constructor: void 0) === String;
},
isArray: function(object) {
return Array.isArray(object);
},
isBoolean: function(object) {
return (object != null) && typeof object === 'boolean';
},
isNumber: function(object) {
return (object != null) && typeof object === 'number';
},
isObject: function(object) {
return typeof object === 'object';
},
isPlainObject: function(object) {
return (object != null ? object.constructor: void 0) === Object;
},
isPrototype: function(object) {
return (object != null) && object === object.constructor.prototype;
},
isDate: function(object) {
return (object != null ? object.constructor: void 0) === Date;
},
isPrimitive: function(object) {
return isString(object) || isBoolean(object) || isNumber(object) || isDate(object);
},
isPrivate: function(property) {
return (property != null ? property[0] : void 0) === '_';
},
values: function(object) {
var key, value, _results;
_results = [];
for (key in object) {
value = object[key];
_results.push(value);
}
return _results;
},
patch: function() {
var patch, pathAndPatch, target;
target = arguments[0],
pathAndPatch = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
patch = JSONMergePatch.create.apply(null, pathAndPatch);
if (isFunction(target != null ? target.patch: void 0)) {
return target.patch(patch);
} else {
return glass.JSONMergePatch.apply(target, patch);
}
},
assert: function(a) {
if (!a) {
return _throwAssertionFailure(JSON.stringify(a));
}
},
assertTrue: function(a) {
if (a !== true) {
return _throwAssertionFailure(JSON.stringify(a) + " != true");
}
},
assertEquals: function(a, b) {
if (JSON.stringify(a) !== JSON.stringify(b)) {
return _throwAssertionFailure(JSON.stringify(a) + ' != ' + JSON.stringify(b));
}
},
getId: {
do: function() {
var counter;
counter = 0;
return function(a) {
var _ref;
if (a === null) {
return '__null__';
}
if (a === void 0) {
return '__undefined__';
}
if (typeof a === 'object' || typeof a === 'function') {
return (_ref = a.id) != null ? _ref: a.id = '__' + (counter++) + '__';
}
return a.toString();
};
}
},
getType: function(path) {
var array, step, value, _i, _len;
array = isArray(path) ? path: path.split('.');
value = global;
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
if (!isFunction(value)) {
throw new Error("Type not found: " + path);
}
return value;
},
test: {
values: function() {
return assertEquals(values({
a: 1,
b: 3,
c: 2
}), [1, 3, 2]);
},
patch: function() {
var x;
x = {
a: {
foo: 1,
bar: 3
},
b: 2
};
patch(x, 'a', 'foo', 5);
return assertEquals(x.a.foo, 5);
}
}
}
},
"runtime\\String.coffee": {
source: "extension: true
properties:
\tstartsWith: (s) -> @slice(0,s.length) is s
\tendsWith: (s) -> @slice(-s.length) is s
\tcontains: (s) -> @indexOf(s) >= 0
\ttoArray: () -> @split ''",
input: "runtime\\String.coffee",
content: {
extension: true,
properties: {
startsWith: function(s) {
return this.slice(0, s.length) === s;
},
endsWith: function(s) {
return this.slice( - s.length) === s;
},
contains: function(s) {
return this.indexOf(s) >= 0;
},
toArray: function() {
return this.split('');
}
}
}
}
}
} | {
options: {
input: {
dir: "runtime",
match: /\.(coffee|pegjs)$/
},
output: {
dir: "www/js"
},
script: {
includes: "www/includes.html",
prefix: "/js/"
},
module: {
main: "glass.js",
prefix: "./www/js/"
},
debug: "buildlog.html",
test: "glass.allTests",
addon: {
pregenerate: {
addUri: function(schema) {
var content, type, typeName, _ref2, _ref3;
_ref2 = schema.types;
for (typeName in _ref2) {
type = _ref2[typeName];
content = type.content;
if (content.extension) {
continue;
}
if ((_ref3 = content.uri) == null) {
content.uri = "global:/" + (content.path.replace(/\./g, '/'));
}
}
return schema;
}
}
},
namespace: ""
},
types: {
"runtime\\glass\\Component.coffee": {
source: "extends: 'Observable'
constructor: (properties) ->
@patch properties
# now site ourselves on our parent
if @parent
id = getId @
patch @parent, id, @
@
properties:
id:
description: 'string which uniquely identifies this component within its parent'
type: 'string'
parent:
description: 'the object that contains this component'
serializable: false
type: 'object'
disposed: false
dispose: -> @patch 'disposed', true
notify: (change) ->
Observable.prototype.notify.apply this, arguments
if change?.disposed
# dispose of any disposable children
for id, child of @ when child?.parent is @
child.dispose?()
# remove self from parent
if @id and @parent
patch @parent, @id, undefined
return
test:
lifecycle: ->
parent = new Component
assert not parent.id?
assert not parent.parent?
child = new Component parent:parent
# id should be automatically assigned
assert isString child.id
assert parent is child.parent
assert parent[child.id] is child
assert parent.hasOwnProperty child.id
parent.dispose()
assert child.disposed is true
assert not parent.hasOwnProperty child.id
nonEnumerability: ->
visibleKeys = (key for key of new Component)
assertEquals visibleKeys, []",
input: "runtime\\glass\\Component.coffee",
content: {
extends: "Observable",
constructor: function(properties) {
var id;
this.patch(properties);
if (this.parent) {
id = getId(this);
patch(this.parent, id, this);
}
return this;
},
properties: {
id: {
description: "string which uniquely identifies this component within its parent",
type: "string"
},
parent: {
description: "the object that contains this component",
serializable: false,
type: "object"
},
disposed: false,
dispose: function() {
return this.patch('disposed', true);
},
notify: function(change) {
var child, id;
Observable.prototype.notify.apply(this, arguments);
if (change != null ? change.disposed: void 0) {
for (id in this) {
child = this[id];
if ((child != null ? child.parent: void 0) === this) {
if (typeof child.dispose === "function") {
child.dispose();
}
}
}
if (this.id && this.parent) {
patch(this.parent, this.id, void 0);
}
}
}
},
test: {
lifecycle: function() {
var child, parent;
parent = new Component;
assert(!(parent.id != null));
assert(!(parent.parent != null));
child = new Component({
parent: parent
});
assert(isString(child.id));
assert(parent === child.parent);
assert(parent[child.id] === child);
assert(parent.hasOwnProperty(child.id));
parent.dispose();
assert(child.disposed === true);
return assert(!parent.hasOwnProperty(child.id));
},
nonEnumerability: function() {
var key, visibleKeys;
visibleKeys = (function() {
var _results;
_results = [];
for (key in new Component) {
_results.push(key);
}
return _results;
})();
return assertEquals(visibleKeys, []);
}
},
name: "Component",
path: "glass.Component",
namespace: "glass"
}
},
"runtime\\glass\\Container.coffee": {
source: "extends: 'Observable'
properties:
watch: ->
unwatch: ->
",
input: "runtime\\glass\\Container.coffee",
content: {
extends: "Observable",
properties: {
watch: function() {},
unwatch: function() {}
},
name: "Container",
path: "glass.Container",
namespace: "glass"
}
},
"runtime\\glass\\Expression\\_parser.pegjs": {
source: "{
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e,array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++)
array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
}
start = expression
expression = conditional
conditional = e:or args:(\"?\" b:expression \":\" c:expression {return [b,c];})* {
while (args.length > 0) {
e = expr(\"?:\", [e].concat(args.pop()));
}
return e;
}
or = a:and b:((\"or\") and)* { return joinLeft(a,b); }
and = a:equality b:((\"and\") equality)* { return joinLeft(a,b); }
equality = a:rel b:((\"==\" / \"!=\") rel)* { return joinLeft(a,b); }
rel = a:sum b:((\"<=\" / \">=\" / \"<\" / \">\") sum)* { return joinLeft(a,b); }
sum = a:product b:((\"+\" / \"-\") product)* { return joinLeft(a,b); }
product = a:not b:((\"*\" / \"div\" / \"mod\") not)* { return joinLeft(a,b); }
not = ops:(s op:(\"!\" / \"~\" / \"+\" / \"-\") { return op; })* b:primary { return unaryRight(ops,b); }
primary = s a:(group / literal / path) s { return a; }
group = \"(\" a:expression \")\" { return a; }
literal = s a:(boolean / number / string / array / object) s { return a; }
boolean = a:(\"true\" / \"false\") { return a == \"true\"; }
number = a:([0-9]+ (\".\" [0-9]+)?) { return parseFloat(toString(a)); }
hex = [a-fA-F0-9]
// as per JSON http://www.json.org
string = a:( '\"' (
[\\u0000-\\u0021\\u0023-\\u005c\\u005e-\\uffff] // all unicode chars except \\ and \"
/ (\"\\\\\" (\"\\\"\" / \"\\\\\" / \"\\/\" / \"b\" / \"f\" / \"n\" / \"r\" / \"t\" / (\"u\" hex hex hex hex)))
)* '\"' )
{ return JSON.parse(toString(a)); }
array = \"[\" a:values \"]\" { return expr(\"array\", a); }
values = first:expression? args:(\",\" b:expression {return b;})* {
if (first != \"\") { args.unshift(first); } return args;
}
object = \"{\" a:keyvalues \"}\" { return expr(\"object\", a); }
keyvalue = s a:string s \":\" b:expression { return [a,b]; }
keyvalues = first:keyvalue? rest:(\",\" b:keyvalue {return b;})* {
if (first) { rest.unshift(first); } return rest;
}
ref = a:(\"//\" / \"/\" / \"$\" / \"**\" / \"*\" / \"..\" / \".\") b:slashProperty? {
e = expr(a); if (b) { b.args.unshift(e); e = b; } return e;
}
/ a:id { return expr(\"ref\", [a]); }
id = a:[a-z_]+ b:[a-z_0-9]* { return a.join('') + b.join(''); }
property = \"/\" a:slashProperty { return a; }
/ \"{\" a:expression \"}\" { return expr(\"{}\", [a]); } // locally scoped expression
/ \"[\" a:expression \"]\" { return expr(\"[]\", [a]); } // predicate
slashProperty = a:(id/number/string) { return expr(\"/\", [a]); }
/ a:(\"..\" / \"*\") { return expr(a, []); }
s \"space\" = [ ]* { return ''; }
path = a:root b:step* {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
}
root = a:implicitDotRoot b:dotStep? { return joinPath(a,b); }
/ explicitDotRoot
step = \".\" a:dotStep { return a; }
/ noDotStep
implicitDotRoot = \"/\" { return expr(\"root\"); }
/ \"@\" { return expr(\"this\"); }
/ \".\" a:\".\"+ { return expr(\"ancestor\", [a.length]); }
explicitDotRoot = a:id { return expr(\"ref\", [a]); }
/ \"*\" { return expr(\"values\", []); }
dotStep = a:(id / string / number) { return expr(\"get\", [a]); }
/ \"*\" { return expr(\"values\", []); }
noDotStep = \"{\" a:expression \"}\" { return expr(\"eval\", [a]); }
/ \"[\" a:expression \"]\" { return expr(\"pred\", [a]); }
/ \"(\" a:values \")\" { return expr(\"call\", [a]); }
",
input: "runtime\\glass\\Expression\\_parser.pegjs",
content: {
value: {
parse: function(input, startRule) {
var parseFunctions = {
"conditional": parse_conditional,
"or": parse_or,
"and": parse_and,
"equality": parse_equality,
"rel": parse_rel,
"sum": parse_sum,
"product": parse_product,
"not": parse_not,
"primary": parse_primary,
"group": parse_group,
"literal": parse_literal,
"boolean": parse_boolean,
"number": parse_number,
"hex": parse_hex,
"string": parse_string,
"array": parse_array,
"values": parse_values,
"object": parse_object,
"keyvalue": parse_keyvalue,
"keyvalues": parse_keyvalues,
"ref": parse_ref,
"id": parse_id,
"property": parse_property,
"slashProperty": parse_slashProperty,
"s": parse_s,
"path": parse_path,
"root": parse_root,
"step": parse_step,
"implicitDotRoot": parse_implicitDotRoot,
"explicitDotRoot": parse_explicitDotRoot,
"dotStep": parse_dotStep,
"noDotStep": parse_noDotStep
};
if (startRule !== undefined) {
if (parseFunctions[startRule] === undefined) {
throw new Error("Invalid rule name: " + quote(startRule) + ".");
}
} else {
startRule = "conditional";
}
var pos = 0;
var reportFailures = 0;
var rightmostFailuresPos = 0;
var rightmostFailuresExpected = [];
function padLeft(input, padding, length) {
var result = input;
var padLength = length - input.length;
for (var i = 0; i < padLength; i++) {
result = padding + result;
}
return result;
}
function escape(ch) {
var charCode = ch.charCodeAt(0);
var escapeChar;
var length;
if (charCode <= 0xFF) {
escapeChar = 'x';
length = 2;
} else {
escapeChar = 'u';
length = 4;
}
return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
}
function matchFailed(failure) {
if (pos < rightmostFailuresPos) {
return;
}
if (pos > rightmostFailuresPos) {
rightmostFailuresPos = pos;
rightmostFailuresExpected = [];
}
rightmostFailuresExpected.push(failure);
}
function parse_conditional() {
var result0, result1, result2, result3, result4, result5;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_or();
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, e, args) {
while (args.length > 0) {
e = expr("?:", [e].concat(args.pop()));
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_or() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_and();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_and() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_equality();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_equality() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_rel();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_rel() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_sum();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_sum() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_product();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_product() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_not();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_not() {
var result0, result1, result2;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = [];
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
while (result1 !== null) {
result0.push(result1);
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
}
if (result0 !== null) {
result1 = parse_primary();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, ops, b) {
return unaryRight(ops, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_primary() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_group();
if (result1 === null) {
result1 = parse_literal();
if (result1 === null) {
result1 = parse_path();
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_group() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_literal() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_boolean();
if (result1 === null) {
result1 = parse_number();
if (result1 === null) {
result1 = parse_string();
if (result1 === null) {
result1 = parse_array();
if (result1 === null) {
result1 = parse_object();
}
}
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_boolean() {
var result0;
var pos0;
pos0 = pos;
if (input.substr(pos, 4) === "true") {
result0 = "true";
pos += 4;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"true\"");
}
}
if (result0 === null) {
if (input.substr(pos, 5) === "false") {
result0 = "false";
pos += 5;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"false\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a == "true";
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_number() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
pos2 = pos;
if (input.charCodeAt(pos) === 46) {
result1 = ".";
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result1 !== null) {
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result3 !== null) {
result2 = [];
while (result3 !== null) {
result2.push(result3);
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result2 = null;
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos2;
}
} else {
result1 = null;
pos = pos2;
}
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return parseFloat(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_hex() {
var result0;
if (/^[a-fA-F0-9]/.test(input.charAt(pos))) {
result0 = input.charAt(pos);
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("[a-fA-F0-9]");
}
}
return result0;
}
function parse_string() {
var result0, result1, result2, result3, result4, result5, result6, result7;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 34) {
result0 = "\"";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result0 !== null) {
result1 = [];
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
}
if (result1 !== null) {
if (input.charCodeAt(pos) === 34) {
result2 = "\"";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return JSON.parse(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_array() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("array", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_values() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_conditional();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, args) {
if (first != "") {
args.unshift(first);
}
return args;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_object() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_keyvalues();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("object", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalue() {
var result0, result1, result2, result3, result4;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_string();
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
if (input.charCodeAt(pos) === 58) {
result3 = ":";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result3 !== null) {
result4 = parse_conditional();
if (result4 !== null) {
result0 = [result0, result1, result2, result3, result4];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return [a, b];
})(pos0, result0[1], result0[4]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalues() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_keyvalue();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, rest) {
if (first) {
rest.unshift(first);
}
return rest;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_ref() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.substr(pos, 2) === "//") {
result0 = "//";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"//\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 36) {
result0 = "$";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"$\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "**") {
result0 = "**";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"**\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
}
}
}
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
e = expr(a);
if (b) {
b.args.unshift(e);
e = b;
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_id() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
result1 = [];
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return a.join('') + b.join('');
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_property() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("{}", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("[]", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_slashProperty() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_number();
if (result0 === null) {
result0 = parse_string();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("/", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(a, []);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_s() {
var result0, result1;
var pos0;
reportFailures++;
pos0 = pos;
result0 = [];
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
while (result1 !== null) {
result0.push(result1);
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
}
if (result0 !== null) {
result0 = (function(offset) {
return '';
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
reportFailures--;
if (reportFailures === 0 && result0 === null) {
matchFailed("space");
}
return result0;
}
function parse_path() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_root();
if (result0 !== null) {
result1 = [];
result2 = parse_step();
while (result2 !== null) {
result1.push(result2);
result2 = parse_step();
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_root() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_implicitDotRoot();
if (result0 !== null) {
result1 = parse_dotStep();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinPath(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_explicitDotRoot();
}
return result0;
}
function parse_step() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
result1 = parse_dotStep();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_noDotStep();
}
return result0;
}
function parse_implicitDotRoot() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("root");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 64) {
result0 = "@";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"@\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("this");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result2 !== null) {
result1 = [];
while (result2 !== null) {
result1.push(result2);
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
} else {
result1 = null;
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ancestor", [a.length]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_explicitDotRoot() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_dotStep() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_string();
if (result0 === null) {
result0 = parse_number();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("get", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_noDotStep() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("eval", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("pred", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("call", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function cleanupExpected(expected) {
expected.sort();
var lastExpected = null;
var cleanExpected = [];
for (var i = 0; i < expected.length; i++) {
if (expected[i] !== lastExpected) {
cleanExpected.push(expected[i]);
lastExpected = expected[i];
}
}
return cleanExpected;
}
function computeErrorPosition() {
/*
* The first idea was to use |String.split| to break the input up to the
* error position along newlines and derive the line and column from
* there. However IE's |split| implementation is so broken that it was
* enough to prevent it.
*/
var line = 1;
var column = 1;
var seenCR = false;
for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
var ch = input.charAt(i);
if (ch === "
") {
if (!seenCR) {
line++;
}
column = 1;
seenCR = false;
} else if (ch === "
" || ch === "\u2028" || ch === "\u2029") {
line++;
column = 1;
seenCR = true;
} else {
column++;
seenCR = false;
}
}
return {
line: line,
column: column
};
}
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e, array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++) array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
var result = parseFunctions[startRule]();
/*
* The parser is now in one of the following three states:
*
* 1. The parser successfully parsed the whole input.
*
* - |result !== null|
* - |pos === input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 2. The parser successfully parsed only a part of the input.
*
* - |result !== null|
* - |pos < input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 3. The parser did not successfully parse any part of the input.
*
* - |result === null|
* - |pos === 0|
* - |rightmostFailuresExpected| contains at least one failure
*
* All code following this comment (including called functions) must
* handle these states.
*/
if (result === null || pos !== input.length) {
var offset = Math.max(pos, rightmostFailuresPos);
var found = offset < input.length ? input.charAt(offset) : null;
var errorPosition = computeErrorPosition();
throw new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column);
}
return result;
},
toSource: function() {
return this._source;
},
SyntaxError: function(expected, found, offset, line, column) {
function buildMessage(expected, found) {
var expectedHumanized, foundHumanized;
switch (expected.length) {
case 0:
expectedHumanized = "end of input";
break;
case 1:
expectedHumanized = expected[0];
break;
default:
expectedHumanized = expected.slice(0, expected.length - 1).join(", ") + " or " + expected[expected.length - 1];
}
foundHumanized = found ? quote(found) : "end of input";
return "Expected " + expectedHumanized + " but " + foundHumanized + " found.";
}
this.name = "SyntaxError";
this.expected = expected;
this.found = found;
this.message = buildMessage(expected, found);
this.offset = offset;
this.line = line;
this.column = column;
}
},
name: "_parser",
path: "glass.Expression._parser",
namespace: "glass.Expression"
}
},
"runtime\\glass\\Expression.coffee": {
source: "constructor: (op, args) ->
@op = op
@args = args if args?
@
properties:
op:
type: 'string'
args:
type: 'array'
test: ->
return
peg = require 'pegjs'
fs = require 'fs'
parserSource = fs.readFileSync 'runtime/glass/Expression/_parser.pegjs', 'utf8'
parser = peg.buildParser parserSource
tests =
\"a.b.c\": {op:\"get\",args:[{op:\"get\",args:[{op:\"ref\",args:[\"a\"]},\"b\"]},\"c\"]}
\"a.1\": {op:\"get\",args:[{op:\"ref\",args:[\"a\"]},1]}
\"true\": true
\"false\": false
\"45.8\": 45.8
\"(45.8)\": 45.8
\"((45.8))\": 45.8
\"alpha\": {op:\"ref\",args:[\"alpha\"]}
\"35 + true * 2\": {op:\"+\", args:[35, {op:\"*\", args:[true,2]}]}
\" 5 * ( 2 + 2 ) \": {op:\"*\", args:[5, {op:\"+\", args:[2,2]}]}
\" ! ! true\": {op:\"!\",args:[{op:\"!\",args:[true]}]}
\"5 + -x\": {op:\"+\",args:[5,{op:\"-\",args:[{op:\"ref\",args:[\"x\"]}]}]}
\"true == 5 >= 2\": {op:\"==\",args:[true,{op:\">=\",args:[5,2]}]}
\"1 or 2 and 3\": {op:\"or\",args:[1,{op:\"and\",args:[2,3]}]}
\"1 ? 2 : 3\": {op:\"?:\",args:[1,2,3]}
\"1 ? 2 : 3 ? 4 : 5\" : {op:\"?:\",args:[1,2,{op:\"?:\",args:[3,4,5]}]}
\"a()(1,2)\" : {op:\"call\",args:[{op:\"call\",args:[{op:\"ref\",args:[\"a\"]},[]]},[1,2]]}
\"@\" : {op:\"this\"}
\"@foo\" : {op:\"get\",args:[{op:\"this\"},\"foo\"]}
'\"hello\"': \"hello\"
'\"\\\\t\\
\\
\\\\b\\\\\\\\foo\\\\\\/\"' : \"\\t
\\b\\\\foo\\/\"
\"[]\": {op:\"array\",args:[]}
\"[1,2]\": {op:\"array\",args:[1,2]}
\"[1+2]\": {op:\"array\",args:[{op:\"+\",args:[1,2]}]}
\"{}\": {op:\"object\",args:[]}
'{\"a\":2}': {op:\"object\",args:[[\"a\",2]]}
'{\"a\":2,\"b\":1+2}': {op:\"object\",args:[[\"a\",2],[\"b\",{op:\"+\",args:[1,2]}]]}
'@\"alpha\"': {op:\"get\",args:[{op:\"this\"},\"alpha\"]}
'*': {op:\"values\",args:[]}
'*.*': {op:\"values\",args:[{op:\"values\",args:[]}]}
\"foo.*\": {op:\"values\",args:[{op:\"ref\",args:[\"foo\"]}]}
\"..\": {op:\"ancestor\",args:[1]}
\"...\": {op:\"ancestor\",args:[2]}
\"@*{1+2}\": {op:\"eval\",args:[{op:\"values\",args:[{op:\"this\"}]},{op:\"+\",args:[1,2]}]}
\"/\": {op:\"root\"}
\"/foo\": {op:\"get\",args:[{op:\"root\"},\"foo\"]}
\"/*\": {op:\"values\",args:[{op:\"root\"}]}
for text, expected of tests
result = parser.parse text
if JSON.stringify(result) is JSON.stringify(expected)
console.log 'Pass: ' + text
else
console.log text, JSON.stringify result
return
",
input: "runtime\\glass\\Expression.coffee",
content: {
constructor: function(op, args) {
this.op = op;
if (args != null) {
this.args = args;
}
return this;
},
properties: {
op: {
type: "string"
},
args: {
type: "array"
}
},
test: function() {
var expected, fs, parser, parserSource, peg, result, tests, text;
return;
peg = require('pegjs');
fs = require('fs');
parserSource = fs.readFileSync('runtime/glass/Expression/_parser.pegjs', 'utf8');
parser = peg.buildParser(parserSource);
tests = {
"a.b.c": {
op: "get",
args: [{
op: "get",
args: [{
op: "ref",
args: ["a"]
},
"b"]
},
"c"]
},
"a.1": {
op: "get",
args: [{
op: "ref",
args: ["a"]
},
1]
},
"true": true,
"false": false,
"45.8": 45.8,
"(45.8)": 45.8,
"((45.8))": 45.8,
"alpha": {
op: "ref",
args: ["alpha"]
},
"35 + true * 2": {
op: "+",
args: [35, {
op: "*",
args: [true, 2]
}]
},
" 5 * ( 2 + 2 ) ": {
op: "*",
args: [5, {
op: "+",
args: [2, 2]
}]
},
" ! ! true": {
op: "!",
args: [{
op: "!",
args: [true]
}]
},
"5 + -x": {
op: "+",
args: [5, {
op: "-",
args: [{
op: "ref",
args: ["x"]
}]
}]
},
"true == 5 >= 2": {
op: "==",
args: [true, {
op: ">=",
args: [5, 2]
}]
},
"1 or 2 and 3": {
op: "or",
args: [1, {
op: "and",
args: [2, 3]
}]
},
"1 ? 2 : 3": {
op: "?:",
args: [1, 2, 3]
},
"1 ? 2 : 3 ? 4 : 5": {
op: "?:",
args: [1, 2, {
op: "?:",
args: [3, 4, 5]
}]
},
"a()(1,2)": {
op: "call",
args: [{
op: "call",
args: [{
op: "ref",
args: ["a"]
},
[]]
},
[1, 2]]
},
"@": {
op: "this"
},
"@foo": {
op: "get",
args: [{
op: "this"
},
"foo"]
},
'"hello"': "hello",
'"\\t
\\b\\\\foo\\\/"': "\t
\b\\foo\/",
"[]": {
op: "array",
args: []
},
"[1,2]": {
op: "array",
args: [1, 2]
},
"[1+2]": {
op: "array",
args: [{
op: "+",
args: [1, 2]
}]
},
"{}": {
op: "object",
args: []
},
'{"a":2}': {
op: "object",
args: [["a", 2]]
},
'{"a":2,"b":1+2}': {
op: "object",
args: [["a", 2], ["b", {
op: "+",
args: [1, 2]
}]]
},
'@"alpha"': {
op: "get",
args: [{
op: "this"
},
"alpha"]
},
'*': {
op: "values",
args: []
},
'*.*': {
op: "values",
args: [{
op: "values",
args: []
}]
},
"foo.*": {
op: "values",
args: [{
op: "ref",
args: ["foo"]
}]
},
"..": {
op: "ancestor",
args: [1]
},
"...": {
op: "ancestor",
args: [2]
},
"@*{1+2}": {
op: "eval",
args: [{
op: "values",
args: [{
op: "this"
}]
},
{
op: "+",
args: [1, 2]
}]
},
"/": {
op: "root"
},
"/foo": {
op: "get",
args: [{
op: "root"
},
"foo"]
},
"/*": {
op: "values",
args: [{
op: "root"
}]
}
};
for (text in tests) {
expected = tests[text];
result = parser.parse(text);
if (JSON.stringify(result) === JSON.stringify(expected)) {
console.log('Pass: ' + text);
} else {
console.log(text, JSON.stringify(result));
}
}
},
name: "Expression",
path: "glass.Expression",
namespace: "glass"
}
},
"runtime\\glass\\JSONMergePatch.coffee": {
source: "
# applies a patch to the target object and returns the resulting target
apply: (target, patch) ->
if target? and target isnt patch and isPlainObject(patch) and not isPrimitive(target)
for key, value of patch
if value is undefined
delete target[key]
else
target[key] = apply target[key], patch[key]
return target
else
return patch
# (path1, path2, path3.., patch) ->
create: ->
if arguments.length is 1
return arguments[0]
result = {}
current = result
for arg, i in arguments when i + 1 < arguments.length
last = i + 2 is arguments.length
current = current[arg] = if last then arguments[arguments.length-1] else {}
result
test: ->
assertEquals {a:{b:12}}, create 'a', 'b', 12
assertEquals {a:3}, apply({a:1,b:2}, {a:3,b:undefined})
",
input: "runtime\\glass\\JSONMergePatch.coffee",
content: {
apply: function(target, patch) {
var key, value;
if ((target != null) && target !== patch && isPlainObject(patch) && !isPrimitive(target)) {
for (key in patch) {
value = patch[key];
if (value === void 0) {
delete target[key];
} else {
target[key] = apply(target[key], patch[key]);
}
}
return target;
} else {
return patch;
}
},
create: function() {
var arg, current, i, last, result, _i, _len;
if (arguments.length === 1) {
return arguments[0];
}
result = {};
current = result;
for (i = _i = 0, _len = arguments.length; _i < _len; i = ++_i) {
arg = arguments[i];
if (! (i + 1 < arguments.length)) {
continue;
}
last = i + 2 === arguments.length;
current = current[arg] = last ? arguments[arguments.length - 1] : {};
}
return result;
},
test: function() {
assertEquals({
a: {
b: 12
}
},
create('a', 'b', 12));
return assertEquals({
a: 3
},
apply({
a: 1,
b: 2
},
{
a: 3,
b: void 0
}));
},
name: "JSONMergePatch",
path: "glass.JSONMergePatch",
namespace: "glass"
}
},
"runtime\\glass\\JSONPointer.coffee": {
source: "# json pointer implementation as per
# http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-05
_decodeStep: (step) -> step.replace(/~1/g, '/').replace(/~0/g, '~')
_getLastStep: (pointer) ->
_decodeStep pointer.substring(pointer.lastIndexOf('/') + 1)
_getParent: (pointer) ->
if not pointer?.length
null
else
pointer.substring(0, pointer.lastIndexOf('/'))
toArray: (pointer) ->
for step in pointer.substring(1).split('/')
_decodeStep step
get: (doc, pointer) ->
value = doc
if pointer.length
path = toArray pointer
for step in path when value?
value = value[step]
value
set: (doc, pointer, value) ->
parentPointer = _getParent pointer
if parentPointer?
parent = get doc, parentPointer
lastStep = _getLastStep pointer
parent[lastStep] = value
value
test: ->
assertEquals _getParent(\"/a/b/c\"), \"/a/b\"
assertEquals _getParent(\"/a\"), \"\"
assertEquals _getParent(\"\"), null
assertEquals _getLastStep(\"/a/b/c\"), \"c\"
assertEquals _getLastStep(\"/a~0~1\"), \"a~/\"
assertEquals _getLastStep(\"\"), \"\"
# tests as per spec
doc = {
\"foo\": [\"bar\", \"baz\"],
\"\": 0,
\"a/b\": 1,
\"c%d\": 2,
\"e^f\": 3,
\"g|h\": 4,
\"i\\\\j\": 5,
\"k\\\"l\": 6,
\" \": 7,
\"m~n\": 8
}
assertEquals get(doc, \"\"), doc
assertEquals get(doc, \"/foo\"), [\"bar\", \"baz\"]
assertEquals get(doc, \"/foo/0\"), \"bar\"
assertEquals get(doc, \"/\"), 0
assertEquals get(doc, \"/a~1b\"), 1
assertEquals get(doc, \"/c%d\"), 2
assertEquals get(doc, \"/e^f\"), 3
assertEquals get(doc, \"/g|h\"), 4
assertEquals get(doc, \"/i\\\\j\"), 5
assertEquals get(doc, \"/k\\\"l\"), 6
assertEquals get(doc, \"/ \"), 7
assertEquals get(doc, \"/m~0n\"), 8
# now test set
assertEquals set(doc, \"/\", 10), 10
assertEquals doc[\"\"], 10
assertEquals set(doc, \"/foo/0\", 10), 10
assertEquals doc.foo[0], 10",
input: "runtime\\glass\\JSONPointer.coffee",
content: {
toArray: function(pointer) {
var step, _i, _len, _ref, _results;
_ref = pointer.substring(1).split('/');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
step = _ref[_i];
_results.push(_decodeStep(step));
}
return _results;
},
get: function(doc, pointer) {
var path, step, value, _i, _len;
value = doc;
if (pointer.length) {
path = toArray(pointer);
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
}
return value;
},
set: function(doc, pointer, value) {
var lastStep, parent, parentPointer;
parentPointer = _getParent(pointer);
if (parentPointer != null) {
parent = get(doc, parentPointer);
lastStep = _getLastStep(pointer);
parent[lastStep] = value;
}
return value;
},
test: function() {
var doc;
assertEquals(_getParent("/a/b/c"), "/a/b");
assertEquals(_getParent("/a"), "");
assertEquals(_getParent(""), null);
assertEquals(_getLastStep("/a/b/c"), "c");
assertEquals(_getLastStep("/a~0~1"), "a~/");
assertEquals(_getLastStep(""), "");
doc = {
"foo": ["bar", "baz"],
"": 0,
"a/b": 1,
"c%d": 2,
"e^f": 3,
"g|h": 4,
"i\\j": 5,
"k\"l": 6,
" ": 7,
"m~n": 8
};
assertEquals(get(doc, ""), doc);
assertEquals(get(doc, "/foo"), ["bar", "baz"]);
assertEquals(get(doc, "/foo/0"), "bar");
assertEquals(get(doc, "/"), 0);
assertEquals(get(doc, "/a~1b"), 1);
assertEquals(get(doc, "/c%d"), 2);
assertEquals(get(doc, "/e^f"), 3);
assertEquals(get(doc, "/g|h"), 4);
assertEquals(get(doc, "/i\\j"), 5);
assertEquals(get(doc, "/k\"l"), 6);
assertEquals(get(doc, "/ "), 7);
assertEquals(get(doc, "/m~0n"), 8);
assertEquals(set(doc, "/", 10), 10);
assertEquals(doc[""], 10);
assertEquals(set(doc, "/foo/0", 10), 10);
return assertEquals(doc.foo[0], 10);
},
name: "JSONPointer",
path: "glass.JSONPointer",
namespace: "glass"
}
},
"runtime\\glass\\Observable.coffee": {
source: "properties:
is: (type) -> @constructor.implements[type.path ? type] is true
watchers:
serializable: false
watch: (property, watcher) ->
if isFunction property
watcher = property
property = ''
id = getId watcher
@patch 'watchers', property, id, watcher
# returns a function which will remove the watch
=> @patch 'watchers', property, getId(watcher), undefined
patch: (change) ->
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
try
JSONMergePatch.apply this, change
catch e
console.log e
finally
@notify change
return
notify: (change) ->
if @watchers?
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
for property, watchers of @watchers
if property.length is 0 or change.hasOwnProperty property
changeArg = if property.length is 0 then change else change[property]
for id, watcher of watchers
watcher this, changeArg
return
toJSON: ->
values =
class: @constructor.path
# serialize statically defined properties
for name, property of @constructor.properties
value = @[name]
if property.serializable isnt false and not isFunction(value)
values[name] = value
# serialize custom properties if allowed by schema
if @constructor.additionalProperties isnt false
for own name, value of @ when not isPrivate name
values[name] = value
values
toString: -> @toJSON()
test:
toJSON: ->
# I need this test later
# on a class that actually has serializable properties
a = new Observable
a.x = 12
a.y = ->
a.z = true
assertEquals a, {class:'glass.Observable', x:12,z:true}
watchAll: ->
# we should actually be able to watch ourselves get added to watchers
# this is very meta.
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch watcher
# now make sure we were called with our own watcher
assert watchArgs[0] is a
assert watchArgs[1]?.watchers?[\"\"]?
# reset watchArgs, and watch something else
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assertEquals a.a, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {a:{b:3}}
# now unwatch
unwatch()
# make sure universal watcher is now empty
assertEquals a.watchers[\"\"], {}
# now reset and do a new event, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
watchProperty: ->
# watch a property
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch \"foo\", watcher
# now make sure we were not called
assert watchArgs.length is 0
# reset watchArgs, and watch something else
a.patch \"foo\", \"b\", 3
assertEquals a.foo, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {b:3}
# now reset and do a different property, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
# now unwatch
unwatch()
# make sure we no longer see foo
watchArgs.length = 0
a.patch \"foo\", \"b\", 4
assert watchArgs.length is 0
",
input: "runtime\\glass\\Observable.coffee",
content: {
properties: {
is: function(type) {
var _ref;
return this.constructor["implements"][(_ref = type.path) != null ? _ref: type] === true;
},
watchers: {
serializable: false
},
watch: function(property, watcher) {
var id, _this = this;
if (isFunction(property)) {
watcher = property;
property = '';
}
id = getId(watcher);
this.patch('watchers', property, id, watcher);
return function() {
return _this.patch('watchers', property, getId(watcher), void 0);
};
},
patch: function(change) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
try {
JSONMergePatch.apply(this, change);
} catch(e) {
console.log(e);
} finally {
this.notify(change);
}
},
notify: function(change) {
var changeArg, id, property, watcher, watchers, _ref;
if (this.watchers != null) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
_ref = this.watchers;
for (property in _ref) {
watchers = _ref[property];
if (property.length === 0 || change.hasOwnProperty(property)) {
changeArg = property.length === 0 ? change: change[property];
for (id in watchers) {
watcher = watchers[id];
watcher(this, changeArg);
}
}
}
}
},
toJSON: function() {
var name, property, value, values, _ref;
values = {
"class": this.constructor.path
};
_ref = this.constructor.properties;
for (name in _ref) {
property = _ref[name];
value = this[name];
if (property.serializable !== false && !isFunction(value)) {
values[name] = value;
}
}
if (this.constructor.additionalProperties !== false) {
for (name in this) {
if (!__hasProp.call(this, name)) continue;
value = this[name];
if (!isPrivate(name)) {
values[name] = value;
}
}
}
return values;
},
toString: function() {
return this.toJSON();
}
},
test: {
toJSON: function() {
var a;
a = new Observable;
a.x = 12;
a.y = function() {};
a.z = true;
return assertEquals(a, {
"class": 'glass.Observable',
x: 12,
z: true
});
},
watchAll: function() {
var a, unwatch, watchArgs, watcher, _ref, _ref1;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch(watcher);
assert(watchArgs[0] === a);
assert(((_ref = watchArgs[1]) != null ? (_ref1 = _ref.watchers) != null ? _ref1[""] : void 0 : void 0) != null);
watchArgs.length = 0;
a.patch("a", "b", 3);
assertEquals(a.a, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
a: {
b: 3
}
});
unwatch();
assertEquals(a.watchers[""], {});
watchArgs.length = 0;
a.patch("a", "b", 3);
return assert(watchArgs.length === 0);
},
watchProperty: function() {
var a, unwatch, watchArgs, watcher;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch("foo", watcher);
assert(watchArgs.length === 0);
a.patch("foo", "b", 3);
assertEquals(a.foo, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
b: 3
});
watchArgs.length = 0;
a.patch("a", "b", 3);
assert(watchArgs.length === 0);
unwatch();
watchArgs.length = 0;
a.patch("foo", "b", 4);
return assert(watchArgs.length === 0);
}
},
name: "Observable",
path: "glass.Observable",
namespace: "glass"
}
},
"runtime\\glass.coffee": {
source: "require:
\tString: true
# runtime type tests
isFunction: (object) -> object? and typeof object is 'function'
isString: (object) -> object?.constructor is String
isArray: (object) -> Array.isArray object
isBoolean: (object) -> object? and typeof object is 'boolean'
isNumber: (object) -> object? and typeof object is 'number'
isObject: (object) -> typeof object is 'object'
isPlainObject: (object) -> object?.constructor is Object
isPrototype: (object) -> object? and object is object.constructor.prototype
isDate: (object) -> object?.constructor is Date
isPrimitive: (object) -> isString(object) or isBoolean(object) or isNumber(object) or isDate(object)
isPrivate: (property) -> property?[0] is '_'
# generic utility functions
values: (object) -> (value for key, value of object)
# generic patch method, uses patch method built into object if present
patch: (target, pathAndPatch...) ->
patch = JSONMergePatch.create.apply null, pathAndPatch
if isFunction target?.patch
target.patch patch
else
glass.JSONMergePatch.apply target, patch
# testing assertions
_getStackLocationInfo: (e, depth) ->
line = e.stack?.split('
')[depth]
return null unless line?
match = /\\(([\\w\\W]*?):(\\d+):(\\d+)\\)/.exec line
return {
file: match[1]
line: parseInt match[2]
column: parseInt match[3]
}
_throwAssertionFailure: (message) ->
try
throw new Error \"Assertion failed: \" + message
catch e
info = _getStackLocationInfo e, 3
if info?
_dumpFile info.file, info.line - 2, info.line + 2, info.line
throw e
_dumpFile: (file, from=1, to, highlight) ->
fs = require 'fs'
return unless fs?
try
content = fs.readFileSync(file).toString()
catch e
content = \"Source not found: #{e}\"
console.log '------------------------------------------------'
console.log file
console.log '------------------------------------------------'
number = 1
if content?
lines = content.split /
|
/
to ?= lines.length
for line in lines
lineNumber = number++
if lineNumber >= from and lineNumber <= to
num = String lineNumber
while num.length < 3
num += ' '
if lineNumber is highlight
`console.log(\"\\033[91m\" + num + \": \" + line + \"\\033[0m\");`
else
`console.log(num + \": \" + line);`
console.log '------------------------------------------------'
assert: (a) ->
_throwAssertionFailure JSON.stringify(a) unless a
assertTrue: (a) ->
_throwAssertionFailure JSON.stringify(a) + \" != true\" unless a is true
assertEquals: (a, b) ->
if JSON.stringify(a) isnt JSON.stringify(b)
_throwAssertionFailure JSON.stringify(a) + ' != ' + JSON.stringify(b)
# gets a unique string identifier for any object
getId:
do: ->
counter = 0
(a) ->
if a is null
return '__null__'
if a is undefined
return '__undefined__'
if typeof a is 'object' or typeof a is 'function'
return a.id ?= '__' + (counter++) + '__'
# 12 == \"12\" under this technique
return a.toString()
getType: (path) ->
array = if isArray path then path else path.split '.'
value = global
for step in path when value?
value = value[step]
throw new Error \"Type not found: #{path}\" unless isFunction value
value
test:
values: ->
assertEquals values({a:1,b:3,c:2}), [1,3,2]
patch: ->
x = {a:{foo:1,bar:3},b:2}
patch x, 'a', 'foo', 5
assertEquals x.a.foo, 5
",
input: "runtime\\glass.coffee",
content: {
require: {
String: true
},
isFunction: function(object) {
return (object != null) && typeof object === 'function';
},
isString: function(object) {
return (object != null ? object.constructor: void 0) === String;
},
isArray: function(object) {
return Array.isArray(object);
},
isBoolean: function(object) {
return (object != null) && typeof object === 'boolean';
},
isNumber: function(object) {
return (object != null) && typeof object === 'number';
},
isObject: function(object) {
return typeof object === 'object';
},
isPlainObject: function(object) {
return (object != null ? object.constructor: void 0) === Object;
},
isPrototype: function(object) {
return (object != null) && object === object.constructor.prototype;
},
isDate: function(object) {
return (object != null ? object.constructor: void 0) === Date;
},
isPrimitive: function(object) {
return isString(object) || isBoolean(object) || isNumber(object) || isDate(object);
},
isPrivate: function(property) {
return (property != null ? property[0] : void 0) === '_';
},
values: function(object) {
var key, value, _results;
_results = [];
for (key in object) {
value = object[key];
_results.push(value);
}
return _results;
},
patch: function() {
var patch, pathAndPatch, target;
target = arguments[0],
pathAndPatch = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
patch = JSONMergePatch.create.apply(null, pathAndPatch);
if (isFunction(target != null ? target.patch: void 0)) {
return target.patch(patch);
} else {
return glass.JSONMergePatch.apply(target, patch);
}
},
assert: function(a) {
if (!a) {
return _throwAssertionFailure(JSON.stringify(a));
}
},
assertTrue: function(a) {
if (a !== true) {
return _throwAssertionFailure(JSON.stringify(a) + " != true");
}
},
assertEquals: function(a, b) {
if (JSON.stringify(a) !== JSON.stringify(b)) {
return _throwAssertionFailure(JSON.stringify(a) + ' != ' + JSON.stringify(b));
}
},
getId: {
do: function() {
var counter;
counter = 0;
return function(a) {
var _ref;
if (a === null) {
return '__null__';
}
if (a === void 0) {
return '__undefined__';
}
if (typeof a === 'object' || typeof a === 'function') {
return (_ref = a.id) != null ? _ref: a.id = '__' + (counter++) + '__';
}
return a.toString();
};
}
},
getType: function(path) {
var array, step, value, _i, _len;
array = isArray(path) ? path: path.split('.');
value = global;
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
if (!isFunction(value)) {
throw new Error("Type not found: " + path);
}
return value;
},
test: {
values: function() {
return assertEquals(values({
a: 1,
b: 3,
c: 2
}), [1, 3, 2]);
},
patch: function() {
var x;
x = {
a: {
foo: 1,
bar: 3
},
b: 2
};
patch(x, 'a', 'foo', 5);
return assertEquals(x.a.foo, 5);
}
},
name: "glass",
path: "glass",
namespace: ""
}
},
"runtime\\String.coffee": {
source: "extension: true
properties:
\tstartsWith: (s) -> @slice(0,s.length) is s
\tendsWith: (s) -> @slice(-s.length) is s
\tcontains: (s) -> @indexOf(s) >= 0
\ttoArray: () -> @split ''",
input: "runtime\\String.coffee",
content: {
extension: true,
properties: {
startsWith: function(s) {
return this.slice(0, s.length) === s;
},
endsWith: function(s) {
return this.slice( - s.length) === s;
},
contains: function(s) {
return this.indexOf(s) >= 0;
},
toArray: function() {
return this.split('');
}
},
name: "String",
path: "String",
namespace: ""
}
}
}
} | {
options: {
input: {
dir: "runtime",
match: /\.(coffee|pegjs)$/
},
output: {
dir: "www/js"
},
script: {
includes: "www/includes.html",
prefix: "/js/"
},
module: {
main: "glass.js",
prefix: "./www/js/"
},
debug: "buildlog.html",
test: "glass.allTests",
addon: {
pregenerate: {
addUri: function(schema) {
var content, type, typeName, _ref2, _ref3;
_ref2 = schema.types;
for (typeName in _ref2) {
type = _ref2[typeName];
content = type.content;
if (content.extension) {
continue;
}
if ((_ref3 = content.uri) == null) {
content.uri = "global:/" + (content.path.replace(/\./g, '/'));
}
}
return schema;
}
}
},
namespace: ""
},
types: {
"glass.Component": {
source: "extends: 'Observable'
constructor: (properties) ->
@patch properties
# now site ourselves on our parent
if @parent
id = getId @
patch @parent, id, @
@
properties:
id:
description: 'string which uniquely identifies this component within its parent'
type: 'string'
parent:
description: 'the object that contains this component'
serializable: false
type: 'object'
disposed: false
dispose: -> @patch 'disposed', true
notify: (change) ->
Observable.prototype.notify.apply this, arguments
if change?.disposed
# dispose of any disposable children
for id, child of @ when child?.parent is @
child.dispose?()
# remove self from parent
if @id and @parent
patch @parent, @id, undefined
return
test:
lifecycle: ->
parent = new Component
assert not parent.id?
assert not parent.parent?
child = new Component parent:parent
# id should be automatically assigned
assert isString child.id
assert parent is child.parent
assert parent[child.id] is child
assert parent.hasOwnProperty child.id
parent.dispose()
assert child.disposed is true
assert not parent.hasOwnProperty child.id
nonEnumerability: ->
visibleKeys = (key for key of new Component)
assertEquals visibleKeys, []",
input: "runtime\\glass\\Component.coffee",
content: {
extends: "Observable",
constructor: function(properties) {
var id;
this.patch(properties);
if (this.parent) {
id = getId(this);
patch(this.parent, id, this);
}
return this;
},
properties: {
id: {
description: "string which uniquely identifies this component within its parent",
type: "string"
},
parent: {
description: "the object that contains this component",
serializable: false,
type: "object"
},
disposed: false,
dispose: function() {
return this.patch('disposed', true);
},
notify: function(change) {
var child, id;
Observable.prototype.notify.apply(this, arguments);
if (change != null ? change.disposed: void 0) {
for (id in this) {
child = this[id];
if ((child != null ? child.parent: void 0) === this) {
if (typeof child.dispose === "function") {
child.dispose();
}
}
}
if (this.id && this.parent) {
patch(this.parent, this.id, void 0);
}
}
}
},
test: {
lifecycle: function() {
var child, parent;
parent = new Component;
assert(!(parent.id != null));
assert(!(parent.parent != null));
child = new Component({
parent: parent
});
assert(isString(child.id));
assert(parent === child.parent);
assert(parent[child.id] === child);
assert(parent.hasOwnProperty(child.id));
parent.dispose();
assert(child.disposed === true);
return assert(!parent.hasOwnProperty(child.id));
},
nonEnumerability: function() {
var key, visibleKeys;
visibleKeys = (function() {
var _results;
_results = [];
for (key in new Component) {
_results.push(key);
}
return _results;
})();
return assertEquals(visibleKeys, []);
}
},
name: "Component",
path: "glass.Component",
namespace: "glass"
}
},
"glass.Container": {
source: "extends: 'Observable'
properties:
watch: ->
unwatch: ->
",
input: "runtime\\glass\\Container.coffee",
content: {
extends: "Observable",
properties: {
watch: function() {},
unwatch: function() {}
},
name: "Container",
path: "glass.Container",
namespace: "glass"
}
},
"glass.Expression._parser": {
source: "{
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e,array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++)
array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
}
start = expression
expression = conditional
conditional = e:or args:(\"?\" b:expression \":\" c:expression {return [b,c];})* {
while (args.length > 0) {
e = expr(\"?:\", [e].concat(args.pop()));
}
return e;
}
or = a:and b:((\"or\") and)* { return joinLeft(a,b); }
and = a:equality b:((\"and\") equality)* { return joinLeft(a,b); }
equality = a:rel b:((\"==\" / \"!=\") rel)* { return joinLeft(a,b); }
rel = a:sum b:((\"<=\" / \">=\" / \"<\" / \">\") sum)* { return joinLeft(a,b); }
sum = a:product b:((\"+\" / \"-\") product)* { return joinLeft(a,b); }
product = a:not b:((\"*\" / \"div\" / \"mod\") not)* { return joinLeft(a,b); }
not = ops:(s op:(\"!\" / \"~\" / \"+\" / \"-\") { return op; })* b:primary { return unaryRight(ops,b); }
primary = s a:(group / literal / path) s { return a; }
group = \"(\" a:expression \")\" { return a; }
literal = s a:(boolean / number / string / array / object) s { return a; }
boolean = a:(\"true\" / \"false\") { return a == \"true\"; }
number = a:([0-9]+ (\".\" [0-9]+)?) { return parseFloat(toString(a)); }
hex = [a-fA-F0-9]
// as per JSON http://www.json.org
string = a:( '\"' (
[\\u0000-\\u0021\\u0023-\\u005c\\u005e-\\uffff] // all unicode chars except \\ and \"
/ (\"\\\\\" (\"\\\"\" / \"\\\\\" / \"\\/\" / \"b\" / \"f\" / \"n\" / \"r\" / \"t\" / (\"u\" hex hex hex hex)))
)* '\"' )
{ return JSON.parse(toString(a)); }
array = \"[\" a:values \"]\" { return expr(\"array\", a); }
values = first:expression? args:(\",\" b:expression {return b;})* {
if (first != \"\") { args.unshift(first); } return args;
}
object = \"{\" a:keyvalues \"}\" { return expr(\"object\", a); }
keyvalue = s a:string s \":\" b:expression { return [a,b]; }
keyvalues = first:keyvalue? rest:(\",\" b:keyvalue {return b;})* {
if (first) { rest.unshift(first); } return rest;
}
ref = a:(\"//\" / \"/\" / \"$\" / \"**\" / \"*\" / \"..\" / \".\") b:slashProperty? {
e = expr(a); if (b) { b.args.unshift(e); e = b; } return e;
}
/ a:id { return expr(\"ref\", [a]); }
id = a:[a-z_]+ b:[a-z_0-9]* { return a.join('') + b.join(''); }
property = \"/\" a:slashProperty { return a; }
/ \"{\" a:expression \"}\" { return expr(\"{}\", [a]); } // locally scoped expression
/ \"[\" a:expression \"]\" { return expr(\"[]\", [a]); } // predicate
slashProperty = a:(id/number/string) { return expr(\"/\", [a]); }
/ a:(\"..\" / \"*\") { return expr(a, []); }
s \"space\" = [ ]* { return ''; }
path = a:root b:step* {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
}
root = a:implicitDotRoot b:dotStep? { return joinPath(a,b); }
/ explicitDotRoot
step = \".\" a:dotStep { return a; }
/ noDotStep
implicitDotRoot = \"/\" { return expr(\"root\"); }
/ \"@\" { return expr(\"this\"); }
/ \".\" a:\".\"+ { return expr(\"ancestor\", [a.length]); }
explicitDotRoot = a:id { return expr(\"ref\", [a]); }
/ \"*\" { return expr(\"values\", []); }
dotStep = a:(id / string / number) { return expr(\"get\", [a]); }
/ \"*\" { return expr(\"values\", []); }
noDotStep = \"{\" a:expression \"}\" { return expr(\"eval\", [a]); }
/ \"[\" a:expression \"]\" { return expr(\"pred\", [a]); }
/ \"(\" a:values \")\" { return expr(\"call\", [a]); }
",
input: "runtime\\glass\\Expression\\_parser.pegjs",
content: {
value: {
parse: function(input, startRule) {
var parseFunctions = {
"conditional": parse_conditional,
"or": parse_or,
"and": parse_and,
"equality": parse_equality,
"rel": parse_rel,
"sum": parse_sum,
"product": parse_product,
"not": parse_not,
"primary": parse_primary,
"group": parse_group,
"literal": parse_literal,
"boolean": parse_boolean,
"number": parse_number,
"hex": parse_hex,
"string": parse_string,
"array": parse_array,
"values": parse_values,
"object": parse_object,
"keyvalue": parse_keyvalue,
"keyvalues": parse_keyvalues,
"ref": parse_ref,
"id": parse_id,
"property": parse_property,
"slashProperty": parse_slashProperty,
"s": parse_s,
"path": parse_path,
"root": parse_root,
"step": parse_step,
"implicitDotRoot": parse_implicitDotRoot,
"explicitDotRoot": parse_explicitDotRoot,
"dotStep": parse_dotStep,
"noDotStep": parse_noDotStep
};
if (startRule !== undefined) {
if (parseFunctions[startRule] === undefined) {
throw new Error("Invalid rule name: " + quote(startRule) + ".");
}
} else {
startRule = "conditional";
}
var pos = 0;
var reportFailures = 0;
var rightmostFailuresPos = 0;
var rightmostFailuresExpected = [];
function padLeft(input, padding, length) {
var result = input;
var padLength = length - input.length;
for (var i = 0; i < padLength; i++) {
result = padding + result;
}
return result;
}
function escape(ch) {
var charCode = ch.charCodeAt(0);
var escapeChar;
var length;
if (charCode <= 0xFF) {
escapeChar = 'x';
length = 2;
} else {
escapeChar = 'u';
length = 4;
}
return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
}
function matchFailed(failure) {
if (pos < rightmostFailuresPos) {
return;
}
if (pos > rightmostFailuresPos) {
rightmostFailuresPos = pos;
rightmostFailuresExpected = [];
}
rightmostFailuresExpected.push(failure);
}
function parse_conditional() {
var result0, result1, result2, result3, result4, result5;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_or();
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, e, args) {
while (args.length > 0) {
e = expr("?:", [e].concat(args.pop()));
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_or() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_and();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_and() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_equality();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_equality() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_rel();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_rel() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_sum();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_sum() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_product();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_product() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_not();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_not() {
var result0, result1, result2;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = [];
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
while (result1 !== null) {
result0.push(result1);
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
}
if (result0 !== null) {
result1 = parse_primary();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, ops, b) {
return unaryRight(ops, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_primary() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_group();
if (result1 === null) {
result1 = parse_literal();
if (result1 === null) {
result1 = parse_path();
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_group() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_literal() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_boolean();
if (result1 === null) {
result1 = parse_number();
if (result1 === null) {
result1 = parse_string();
if (result1 === null) {
result1 = parse_array();
if (result1 === null) {
result1 = parse_object();
}
}
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_boolean() {
var result0;
var pos0;
pos0 = pos;
if (input.substr(pos, 4) === "true") {
result0 = "true";
pos += 4;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"true\"");
}
}
if (result0 === null) {
if (input.substr(pos, 5) === "false") {
result0 = "false";
pos += 5;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"false\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a == "true";
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_number() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
pos2 = pos;
if (input.charCodeAt(pos) === 46) {
result1 = ".";
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result1 !== null) {
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result3 !== null) {
result2 = [];
while (result3 !== null) {
result2.push(result3);
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result2 = null;
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos2;
}
} else {
result1 = null;
pos = pos2;
}
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return parseFloat(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_hex() {
var result0;
if (/^[a-fA-F0-9]/.test(input.charAt(pos))) {
result0 = input.charAt(pos);
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("[a-fA-F0-9]");
}
}
return result0;
}
function parse_string() {
var result0, result1, result2, result3, result4, result5, result6, result7;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 34) {
result0 = "\"";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result0 !== null) {
result1 = [];
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
}
if (result1 !== null) {
if (input.charCodeAt(pos) === 34) {
result2 = "\"";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return JSON.parse(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_array() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("array", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_values() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_conditional();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, args) {
if (first != "") {
args.unshift(first);
}
return args;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_object() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_keyvalues();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("object", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalue() {
var result0, result1, result2, result3, result4;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_string();
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
if (input.charCodeAt(pos) === 58) {
result3 = ":";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result3 !== null) {
result4 = parse_conditional();
if (result4 !== null) {
result0 = [result0, result1, result2, result3, result4];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return [a, b];
})(pos0, result0[1], result0[4]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalues() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_keyvalue();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, rest) {
if (first) {
rest.unshift(first);
}
return rest;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_ref() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.substr(pos, 2) === "//") {
result0 = "//";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"//\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 36) {
result0 = "$";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"$\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "**") {
result0 = "**";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"**\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
}
}
}
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
e = expr(a);
if (b) {
b.args.unshift(e);
e = b;
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_id() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
result1 = [];
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return a.join('') + b.join('');
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_property() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("{}", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("[]", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_slashProperty() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_number();
if (result0 === null) {
result0 = parse_string();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("/", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(a, []);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_s() {
var result0, result1;
var pos0;
reportFailures++;
pos0 = pos;
result0 = [];
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
while (result1 !== null) {
result0.push(result1);
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
}
if (result0 !== null) {
result0 = (function(offset) {
return '';
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
reportFailures--;
if (reportFailures === 0 && result0 === null) {
matchFailed("space");
}
return result0;
}
function parse_path() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_root();
if (result0 !== null) {
result1 = [];
result2 = parse_step();
while (result2 !== null) {
result1.push(result2);
result2 = parse_step();
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_root() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_implicitDotRoot();
if (result0 !== null) {
result1 = parse_dotStep();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinPath(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_explicitDotRoot();
}
return result0;
}
function parse_step() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
result1 = parse_dotStep();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_noDotStep();
}
return result0;
}
function parse_implicitDotRoot() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("root");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 64) {
result0 = "@";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"@\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("this");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result2 !== null) {
result1 = [];
while (result2 !== null) {
result1.push(result2);
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
} else {
result1 = null;
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ancestor", [a.length]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_explicitDotRoot() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_dotStep() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_string();
if (result0 === null) {
result0 = parse_number();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("get", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_noDotStep() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("eval", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("pred", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("call", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function cleanupExpected(expected) {
expected.sort();
var lastExpected = null;
var cleanExpected = [];
for (var i = 0; i < expected.length; i++) {
if (expected[i] !== lastExpected) {
cleanExpected.push(expected[i]);
lastExpected = expected[i];
}
}
return cleanExpected;
}
function computeErrorPosition() {
/*
* The first idea was to use |String.split| to break the input up to the
* error position along newlines and derive the line and column from
* there. However IE's |split| implementation is so broken that it was
* enough to prevent it.
*/
var line = 1;
var column = 1;
var seenCR = false;
for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
var ch = input.charAt(i);
if (ch === "
") {
if (!seenCR) {
line++;
}
column = 1;
seenCR = false;
} else if (ch === "
" || ch === "\u2028" || ch === "\u2029") {
line++;
column = 1;
seenCR = true;
} else {
column++;
seenCR = false;
}
}
return {
line: line,
column: column
};
}
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e, array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++) array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
var result = parseFunctions[startRule]();
/*
* The parser is now in one of the following three states:
*
* 1. The parser successfully parsed the whole input.
*
* - |result !== null|
* - |pos === input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 2. The parser successfully parsed only a part of the input.
*
* - |result !== null|
* - |pos < input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 3. The parser did not successfully parse any part of the input.
*
* - |result === null|
* - |pos === 0|
* - |rightmostFailuresExpected| contains at least one failure
*
* All code following this comment (including called functions) must
* handle these states.
*/
if (result === null || pos !== input.length) {
var offset = Math.max(pos, rightmostFailuresPos);
var found = offset < input.length ? input.charAt(offset) : null;
var errorPosition = computeErrorPosition();
throw new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column);
}
return result;
},
toSource: function() {
return this._source;
},
SyntaxError: function(expected, found, offset, line, column) {
function buildMessage(expected, found) {
var expectedHumanized, foundHumanized;
switch (expected.length) {
case 0:
expectedHumanized = "end of input";
break;
case 1:
expectedHumanized = expected[0];
break;
default:
expectedHumanized = expected.slice(0, expected.length - 1).join(", ") + " or " + expected[expected.length - 1];
}
foundHumanized = found ? quote(found) : "end of input";
return "Expected " + expectedHumanized + " but " + foundHumanized + " found.";
}
this.name = "SyntaxError";
this.expected = expected;
this.found = found;
this.message = buildMessage(expected, found);
this.offset = offset;
this.line = line;
this.column = column;
}
},
name: "_parser",
path: "glass.Expression._parser",
namespace: "glass.Expression"
}
},
"glass.Expression": {
source: "constructor: (op, args) ->
@op = op
@args = args if args?
@
properties:
op:
type: 'string'
args:
type: 'array'
test: ->
return
peg = require 'pegjs'
fs = require 'fs'
parserSource = fs.readFileSync 'runtime/glass/Expression/_parser.pegjs', 'utf8'
parser = peg.buildParser parserSource
tests =
\"a.b.c\": {op:\"get\",args:[{op:\"get\",args:[{op:\"ref\",args:[\"a\"]},\"b\"]},\"c\"]}
\"a.1\": {op:\"get\",args:[{op:\"ref\",args:[\"a\"]},1]}
\"true\": true
\"false\": false
\"45.8\": 45.8
\"(45.8)\": 45.8
\"((45.8))\": 45.8
\"alpha\": {op:\"ref\",args:[\"alpha\"]}
\"35 + true * 2\": {op:\"+\", args:[35, {op:\"*\", args:[true,2]}]}
\" 5 * ( 2 + 2 ) \": {op:\"*\", args:[5, {op:\"+\", args:[2,2]}]}
\" ! ! true\": {op:\"!\",args:[{op:\"!\",args:[true]}]}
\"5 + -x\": {op:\"+\",args:[5,{op:\"-\",args:[{op:\"ref\",args:[\"x\"]}]}]}
\"true == 5 >= 2\": {op:\"==\",args:[true,{op:\">=\",args:[5,2]}]}
\"1 or 2 and 3\": {op:\"or\",args:[1,{op:\"and\",args:[2,3]}]}
\"1 ? 2 : 3\": {op:\"?:\",args:[1,2,3]}
\"1 ? 2 : 3 ? 4 : 5\" : {op:\"?:\",args:[1,2,{op:\"?:\",args:[3,4,5]}]}
\"a()(1,2)\" : {op:\"call\",args:[{op:\"call\",args:[{op:\"ref\",args:[\"a\"]},[]]},[1,2]]}
\"@\" : {op:\"this\"}
\"@foo\" : {op:\"get\",args:[{op:\"this\"},\"foo\"]}
'\"hello\"': \"hello\"
'\"\\\\t\\
\\
\\\\b\\\\\\\\foo\\\\\\/\"' : \"\\t
\\b\\\\foo\\/\"
\"[]\": {op:\"array\",args:[]}
\"[1,2]\": {op:\"array\",args:[1,2]}
\"[1+2]\": {op:\"array\",args:[{op:\"+\",args:[1,2]}]}
\"{}\": {op:\"object\",args:[]}
'{\"a\":2}': {op:\"object\",args:[[\"a\",2]]}
'{\"a\":2,\"b\":1+2}': {op:\"object\",args:[[\"a\",2],[\"b\",{op:\"+\",args:[1,2]}]]}
'@\"alpha\"': {op:\"get\",args:[{op:\"this\"},\"alpha\"]}
'*': {op:\"values\",args:[]}
'*.*': {op:\"values\",args:[{op:\"values\",args:[]}]}
\"foo.*\": {op:\"values\",args:[{op:\"ref\",args:[\"foo\"]}]}
\"..\": {op:\"ancestor\",args:[1]}
\"...\": {op:\"ancestor\",args:[2]}
\"@*{1+2}\": {op:\"eval\",args:[{op:\"values\",args:[{op:\"this\"}]},{op:\"+\",args:[1,2]}]}
\"/\": {op:\"root\"}
\"/foo\": {op:\"get\",args:[{op:\"root\"},\"foo\"]}
\"/*\": {op:\"values\",args:[{op:\"root\"}]}
for text, expected of tests
result = parser.parse text
if JSON.stringify(result) is JSON.stringify(expected)
console.log 'Pass: ' + text
else
console.log text, JSON.stringify result
return
",
input: "runtime\\glass\\Expression.coffee",
content: {
constructor: function(op, args) {
this.op = op;
if (args != null) {
this.args = args;
}
return this;
},
properties: {
op: {
type: "string"
},
args: {
type: "array"
}
},
test: function() {
var expected, fs, parser, parserSource, peg, result, tests, text;
return;
peg = require('pegjs');
fs = require('fs');
parserSource = fs.readFileSync('runtime/glass/Expression/_parser.pegjs', 'utf8');
parser = peg.buildParser(parserSource);
tests = {
"a.b.c": {
op: "get",
args: [{
op: "get",
args: [{
op: "ref",
args: ["a"]
},
"b"]
},
"c"]
},
"a.1": {
op: "get",
args: [{
op: "ref",
args: ["a"]
},
1]
},
"true": true,
"false": false,
"45.8": 45.8,
"(45.8)": 45.8,
"((45.8))": 45.8,
"alpha": {
op: "ref",
args: ["alpha"]
},
"35 + true * 2": {
op: "+",
args: [35, {
op: "*",
args: [true, 2]
}]
},
" 5 * ( 2 + 2 ) ": {
op: "*",
args: [5, {
op: "+",
args: [2, 2]
}]
},
" ! ! true": {
op: "!",
args: [{
op: "!",
args: [true]
}]
},
"5 + -x": {
op: "+",
args: [5, {
op: "-",
args: [{
op: "ref",
args: ["x"]
}]
}]
},
"true == 5 >= 2": {
op: "==",
args: [true, {
op: ">=",
args: [5, 2]
}]
},
"1 or 2 and 3": {
op: "or",
args: [1, {
op: "and",
args: [2, 3]
}]
},
"1 ? 2 : 3": {
op: "?:",
args: [1, 2, 3]
},
"1 ? 2 : 3 ? 4 : 5": {
op: "?:",
args: [1, 2, {
op: "?:",
args: [3, 4, 5]
}]
},
"a()(1,2)": {
op: "call",
args: [{
op: "call",
args: [{
op: "ref",
args: ["a"]
},
[]]
},
[1, 2]]
},
"@": {
op: "this"
},
"@foo": {
op: "get",
args: [{
op: "this"
},
"foo"]
},
'"hello"': "hello",
'"\\t
\\b\\\\foo\\\/"': "\t
\b\\foo\/",
"[]": {
op: "array",
args: []
},
"[1,2]": {
op: "array",
args: [1, 2]
},
"[1+2]": {
op: "array",
args: [{
op: "+",
args: [1, 2]
}]
},
"{}": {
op: "object",
args: []
},
'{"a":2}': {
op: "object",
args: [["a", 2]]
},
'{"a":2,"b":1+2}': {
op: "object",
args: [["a", 2], ["b", {
op: "+",
args: [1, 2]
}]]
},
'@"alpha"': {
op: "get",
args: [{
op: "this"
},
"alpha"]
},
'*': {
op: "values",
args: []
},
'*.*': {
op: "values",
args: [{
op: "values",
args: []
}]
},
"foo.*": {
op: "values",
args: [{
op: "ref",
args: ["foo"]
}]
},
"..": {
op: "ancestor",
args: [1]
},
"...": {
op: "ancestor",
args: [2]
},
"@*{1+2}": {
op: "eval",
args: [{
op: "values",
args: [{
op: "this"
}]
},
{
op: "+",
args: [1, 2]
}]
},
"/": {
op: "root"
},
"/foo": {
op: "get",
args: [{
op: "root"
},
"foo"]
},
"/*": {
op: "values",
args: [{
op: "root"
}]
}
};
for (text in tests) {
expected = tests[text];
result = parser.parse(text);
if (JSON.stringify(result) === JSON.stringify(expected)) {
console.log('Pass: ' + text);
} else {
console.log(text, JSON.stringify(result));
}
}
},
name: "Expression",
path: "glass.Expression",
namespace: "glass"
}
},
"glass.JSONMergePatch": {
source: "
# applies a patch to the target object and returns the resulting target
apply: (target, patch) ->
if target? and target isnt patch and isPlainObject(patch) and not isPrimitive(target)
for key, value of patch
if value is undefined
delete target[key]
else
target[key] = apply target[key], patch[key]
return target
else
return patch
# (path1, path2, path3.., patch) ->
create: ->
if arguments.length is 1
return arguments[0]
result = {}
current = result
for arg, i in arguments when i + 1 < arguments.length
last = i + 2 is arguments.length
current = current[arg] = if last then arguments[arguments.length-1] else {}
result
test: ->
assertEquals {a:{b:12}}, create 'a', 'b', 12
assertEquals {a:3}, apply({a:1,b:2}, {a:3,b:undefined})
",
input: "runtime\\glass\\JSONMergePatch.coffee",
content: {
apply: function(target, patch) {
var key, value;
if ((target != null) && target !== patch && isPlainObject(patch) && !isPrimitive(target)) {
for (key in patch) {
value = patch[key];
if (value === void 0) {
delete target[key];
} else {
target[key] = apply(target[key], patch[key]);
}
}
return target;
} else {
return patch;
}
},
create: function() {
var arg, current, i, last, result, _i, _len;
if (arguments.length === 1) {
return arguments[0];
}
result = {};
current = result;
for (i = _i = 0, _len = arguments.length; _i < _len; i = ++_i) {
arg = arguments[i];
if (! (i + 1 < arguments.length)) {
continue;
}
last = i + 2 === arguments.length;
current = current[arg] = last ? arguments[arguments.length - 1] : {};
}
return result;
},
test: function() {
assertEquals({
a: {
b: 12
}
},
create('a', 'b', 12));
return assertEquals({
a: 3
},
apply({
a: 1,
b: 2
},
{
a: 3,
b: void 0
}));
},
name: "JSONMergePatch",
path: "glass.JSONMergePatch",
namespace: "glass"
}
},
"glass.JSONPointer": {
source: "# json pointer implementation as per
# http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-05
_decodeStep: (step) -> step.replace(/~1/g, '/').replace(/~0/g, '~')
_getLastStep: (pointer) ->
_decodeStep pointer.substring(pointer.lastIndexOf('/') + 1)
_getParent: (pointer) ->
if not pointer?.length
null
else
pointer.substring(0, pointer.lastIndexOf('/'))
toArray: (pointer) ->
for step in pointer.substring(1).split('/')
_decodeStep step
get: (doc, pointer) ->
value = doc
if pointer.length
path = toArray pointer
for step in path when value?
value = value[step]
value
set: (doc, pointer, value) ->
parentPointer = _getParent pointer
if parentPointer?
parent = get doc, parentPointer
lastStep = _getLastStep pointer
parent[lastStep] = value
value
test: ->
assertEquals _getParent(\"/a/b/c\"), \"/a/b\"
assertEquals _getParent(\"/a\"), \"\"
assertEquals _getParent(\"\"), null
assertEquals _getLastStep(\"/a/b/c\"), \"c\"
assertEquals _getLastStep(\"/a~0~1\"), \"a~/\"
assertEquals _getLastStep(\"\"), \"\"
# tests as per spec
doc = {
\"foo\": [\"bar\", \"baz\"],
\"\": 0,
\"a/b\": 1,
\"c%d\": 2,
\"e^f\": 3,
\"g|h\": 4,
\"i\\\\j\": 5,
\"k\\\"l\": 6,
\" \": 7,
\"m~n\": 8
}
assertEquals get(doc, \"\"), doc
assertEquals get(doc, \"/foo\"), [\"bar\", \"baz\"]
assertEquals get(doc, \"/foo/0\"), \"bar\"
assertEquals get(doc, \"/\"), 0
assertEquals get(doc, \"/a~1b\"), 1
assertEquals get(doc, \"/c%d\"), 2
assertEquals get(doc, \"/e^f\"), 3
assertEquals get(doc, \"/g|h\"), 4
assertEquals get(doc, \"/i\\\\j\"), 5
assertEquals get(doc, \"/k\\\"l\"), 6
assertEquals get(doc, \"/ \"), 7
assertEquals get(doc, \"/m~0n\"), 8
# now test set
assertEquals set(doc, \"/\", 10), 10
assertEquals doc[\"\"], 10
assertEquals set(doc, \"/foo/0\", 10), 10
assertEquals doc.foo[0], 10",
input: "runtime\\glass\\JSONPointer.coffee",
content: {
toArray: function(pointer) {
var step, _i, _len, _ref, _results;
_ref = pointer.substring(1).split('/');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
step = _ref[_i];
_results.push(_decodeStep(step));
}
return _results;
},
get: function(doc, pointer) {
var path, step, value, _i, _len;
value = doc;
if (pointer.length) {
path = toArray(pointer);
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
}
return value;
},
set: function(doc, pointer, value) {
var lastStep, parent, parentPointer;
parentPointer = _getParent(pointer);
if (parentPointer != null) {
parent = get(doc, parentPointer);
lastStep = _getLastStep(pointer);
parent[lastStep] = value;
}
return value;
},
test: function() {
var doc;
assertEquals(_getParent("/a/b/c"), "/a/b");
assertEquals(_getParent("/a"), "");
assertEquals(_getParent(""), null);
assertEquals(_getLastStep("/a/b/c"), "c");
assertEquals(_getLastStep("/a~0~1"), "a~/");
assertEquals(_getLastStep(""), "");
doc = {
"foo": ["bar", "baz"],
"": 0,
"a/b": 1,
"c%d": 2,
"e^f": 3,
"g|h": 4,
"i\\j": 5,
"k\"l": 6,
" ": 7,
"m~n": 8
};
assertEquals(get(doc, ""), doc);
assertEquals(get(doc, "/foo"), ["bar", "baz"]);
assertEquals(get(doc, "/foo/0"), "bar");
assertEquals(get(doc, "/"), 0);
assertEquals(get(doc, "/a~1b"), 1);
assertEquals(get(doc, "/c%d"), 2);
assertEquals(get(doc, "/e^f"), 3);
assertEquals(get(doc, "/g|h"), 4);
assertEquals(get(doc, "/i\\j"), 5);
assertEquals(get(doc, "/k\"l"), 6);
assertEquals(get(doc, "/ "), 7);
assertEquals(get(doc, "/m~0n"), 8);
assertEquals(set(doc, "/", 10), 10);
assertEquals(doc[""], 10);
assertEquals(set(doc, "/foo/0", 10), 10);
return assertEquals(doc.foo[0], 10);
},
name: "JSONPointer",
path: "glass.JSONPointer",
namespace: "glass"
}
},
"glass.Observable": {
source: "properties:
is: (type) -> @constructor.implements[type.path ? type] is true
watchers:
serializable: false
watch: (property, watcher) ->
if isFunction property
watcher = property
property = ''
id = getId watcher
@patch 'watchers', property, id, watcher
# returns a function which will remove the watch
=> @patch 'watchers', property, getId(watcher), undefined
patch: (change) ->
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
try
JSONMergePatch.apply this, change
catch e
console.log e
finally
@notify change
return
notify: (change) ->
if @watchers?
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
for property, watchers of @watchers
if property.length is 0 or change.hasOwnProperty property
changeArg = if property.length is 0 then change else change[property]
for id, watcher of watchers
watcher this, changeArg
return
toJSON: ->
values =
class: @constructor.path
# serialize statically defined properties
for name, property of @constructor.properties
value = @[name]
if property.serializable isnt false and not isFunction(value)
values[name] = value
# serialize custom properties if allowed by schema
if @constructor.additionalProperties isnt false
for own name, value of @ when not isPrivate name
values[name] = value
values
toString: -> @toJSON()
test:
toJSON: ->
# I need this test later
# on a class that actually has serializable properties
a = new Observable
a.x = 12
a.y = ->
a.z = true
assertEquals a, {class:'glass.Observable', x:12,z:true}
watchAll: ->
# we should actually be able to watch ourselves get added to watchers
# this is very meta.
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch watcher
# now make sure we were called with our own watcher
assert watchArgs[0] is a
assert watchArgs[1]?.watchers?[\"\"]?
# reset watchArgs, and watch something else
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assertEquals a.a, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {a:{b:3}}
# now unwatch
unwatch()
# make sure universal watcher is now empty
assertEquals a.watchers[\"\"], {}
# now reset and do a new event, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
watchProperty: ->
# watch a property
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch \"foo\", watcher
# now make sure we were not called
assert watchArgs.length is 0
# reset watchArgs, and watch something else
a.patch \"foo\", \"b\", 3
assertEquals a.foo, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {b:3}
# now reset and do a different property, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
# now unwatch
unwatch()
# make sure we no longer see foo
watchArgs.length = 0
a.patch \"foo\", \"b\", 4
assert watchArgs.length is 0
",
input: "runtime\\glass\\Observable.coffee",
content: {
properties: {
is: function(type) {
var _ref;
return this.constructor["implements"][(_ref = type.path) != null ? _ref: type] === true;
},
watchers: {
serializable: false
},
watch: function(property, watcher) {
var id, _this = this;
if (isFunction(property)) {
watcher = property;
property = '';
}
id = getId(watcher);
this.patch('watchers', property, id, watcher);
return function() {
return _this.patch('watchers', property, getId(watcher), void 0);
};
},
patch: function(change) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
try {
JSONMergePatch.apply(this, change);
} catch(e) {
console.log(e);
} finally {
this.notify(change);
}
},
notify: function(change) {
var changeArg, id, property, watcher, watchers, _ref;
if (this.watchers != null) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
_ref = this.watchers;
for (property in _ref) {
watchers = _ref[property];
if (property.length === 0 || change.hasOwnProperty(property)) {
changeArg = property.length === 0 ? change: change[property];
for (id in watchers) {
watcher = watchers[id];
watcher(this, changeArg);
}
}
}
}
},
toJSON: function() {
var name, property, value, values, _ref;
values = {
"class": this.constructor.path
};
_ref = this.constructor.properties;
for (name in _ref) {
property = _ref[name];
value = this[name];
if (property.serializable !== false && !isFunction(value)) {
values[name] = value;
}
}
if (this.constructor.additionalProperties !== false) {
for (name in this) {
if (!__hasProp.call(this, name)) continue;
value = this[name];
if (!isPrivate(name)) {
values[name] = value;
}
}
}
return values;
},
toString: function() {
return this.toJSON();
}
},
test: {
toJSON: function() {
var a;
a = new Observable;
a.x = 12;
a.y = function() {};
a.z = true;
return assertEquals(a, {
"class": 'glass.Observable',
x: 12,
z: true
});
},
watchAll: function() {
var a, unwatch, watchArgs, watcher, _ref, _ref1;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch(watcher);
assert(watchArgs[0] === a);
assert(((_ref = watchArgs[1]) != null ? (_ref1 = _ref.watchers) != null ? _ref1[""] : void 0 : void 0) != null);
watchArgs.length = 0;
a.patch("a", "b", 3);
assertEquals(a.a, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
a: {
b: 3
}
});
unwatch();
assertEquals(a.watchers[""], {});
watchArgs.length = 0;
a.patch("a", "b", 3);
return assert(watchArgs.length === 0);
},
watchProperty: function() {
var a, unwatch, watchArgs, watcher;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch("foo", watcher);
assert(watchArgs.length === 0);
a.patch("foo", "b", 3);
assertEquals(a.foo, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
b: 3
});
watchArgs.length = 0;
a.patch("a", "b", 3);
assert(watchArgs.length === 0);
unwatch();
watchArgs.length = 0;
a.patch("foo", "b", 4);
return assert(watchArgs.length === 0);
}
},
name: "Observable",
path: "glass.Observable",
namespace: "glass"
}
},
glass: {
source: "require:
\tString: true
# runtime type tests
isFunction: (object) -> object? and typeof object is 'function'
isString: (object) -> object?.constructor is String
isArray: (object) -> Array.isArray object
isBoolean: (object) -> object? and typeof object is 'boolean'
isNumber: (object) -> object? and typeof object is 'number'
isObject: (object) -> typeof object is 'object'
isPlainObject: (object) -> object?.constructor is Object
isPrototype: (object) -> object? and object is object.constructor.prototype
isDate: (object) -> object?.constructor is Date
isPrimitive: (object) -> isString(object) or isBoolean(object) or isNumber(object) or isDate(object)
isPrivate: (property) -> property?[0] is '_'
# generic utility functions
values: (object) -> (value for key, value of object)
# generic patch method, uses patch method built into object if present
patch: (target, pathAndPatch...) ->
patch = JSONMergePatch.create.apply null, pathAndPatch
if isFunction target?.patch
target.patch patch
else
glass.JSONMergePatch.apply target, patch
# testing assertions
_getStackLocationInfo: (e, depth) ->
line = e.stack?.split('
')[depth]
return null unless line?
match = /\\(([\\w\\W]*?):(\\d+):(\\d+)\\)/.exec line
return {
file: match[1]
line: parseInt match[2]
column: parseInt match[3]
}
_throwAssertionFailure: (message) ->
try
throw new Error \"Assertion failed: \" + message
catch e
info = _getStackLocationInfo e, 3
if info?
_dumpFile info.file, info.line - 2, info.line + 2, info.line
throw e
_dumpFile: (file, from=1, to, highlight) ->
fs = require 'fs'
return unless fs?
try
content = fs.readFileSync(file).toString()
catch e
content = \"Source not found: #{e}\"
console.log '------------------------------------------------'
console.log file
console.log '------------------------------------------------'
number = 1
if content?
lines = content.split /
|
/
to ?= lines.length
for line in lines
lineNumber = number++
if lineNumber >= from and lineNumber <= to
num = String lineNumber
while num.length < 3
num += ' '
if lineNumber is highlight
`console.log(\"\\033[91m\" + num + \": \" + line + \"\\033[0m\");`
else
`console.log(num + \": \" + line);`
console.log '------------------------------------------------'
assert: (a) ->
_throwAssertionFailure JSON.stringify(a) unless a
assertTrue: (a) ->
_throwAssertionFailure JSON.stringify(a) + \" != true\" unless a is true
assertEquals: (a, b) ->
if JSON.stringify(a) isnt JSON.stringify(b)
_throwAssertionFailure JSON.stringify(a) + ' != ' + JSON.stringify(b)
# gets a unique string identifier for any object
getId:
do: ->
counter = 0
(a) ->
if a is null
return '__null__'
if a is undefined
return '__undefined__'
if typeof a is 'object' or typeof a is 'function'
return a.id ?= '__' + (counter++) + '__'
# 12 == \"12\" under this technique
return a.toString()
getType: (path) ->
array = if isArray path then path else path.split '.'
value = global
for step in path when value?
value = value[step]
throw new Error \"Type not found: #{path}\" unless isFunction value
value
test:
values: ->
assertEquals values({a:1,b:3,c:2}), [1,3,2]
patch: ->
x = {a:{foo:1,bar:3},b:2}
patch x, 'a', 'foo', 5
assertEquals x.a.foo, 5
",
input: "runtime\\glass.coffee",
content: {
require: {
String: true
},
isFunction: function(object) {
return (object != null) && typeof object === 'function';
},
isString: function(object) {
return (object != null ? object.constructor: void 0) === String;
},
isArray: function(object) {
return Array.isArray(object);
},
isBoolean: function(object) {
return (object != null) && typeof object === 'boolean';
},
isNumber: function(object) {
return (object != null) && typeof object === 'number';
},
isObject: function(object) {
return typeof object === 'object';
},
isPlainObject: function(object) {
return (object != null ? object.constructor: void 0) === Object;
},
isPrototype: function(object) {
return (object != null) && object === object.constructor.prototype;
},
isDate: function(object) {
return (object != null ? object.constructor: void 0) === Date;
},
isPrimitive: function(object) {
return isString(object) || isBoolean(object) || isNumber(object) || isDate(object);
},
isPrivate: function(property) {
return (property != null ? property[0] : void 0) === '_';
},
values: function(object) {
var key, value, _results;
_results = [];
for (key in object) {
value = object[key];
_results.push(value);
}
return _results;
},
patch: function() {
var patch, pathAndPatch, target;
target = arguments[0],
pathAndPatch = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
patch = JSONMergePatch.create.apply(null, pathAndPatch);
if (isFunction(target != null ? target.patch: void 0)) {
return target.patch(patch);
} else {
return glass.JSONMergePatch.apply(target, patch);
}
},
assert: function(a) {
if (!a) {
return _throwAssertionFailure(JSON.stringify(a));
}
},
assertTrue: function(a) {
if (a !== true) {
return _throwAssertionFailure(JSON.stringify(a) + " != true");
}
},
assertEquals: function(a, b) {
if (JSON.stringify(a) !== JSON.stringify(b)) {
return _throwAssertionFailure(JSON.stringify(a) + ' != ' + JSON.stringify(b));
}
},
getId: {
do: function() {
var counter;
counter = 0;
return function(a) {
var _ref;
if (a === null) {
return '__null__';
}
if (a === void 0) {
return '__undefined__';
}
if (typeof a === 'object' || typeof a === 'function') {
return (_ref = a.id) != null ? _ref: a.id = '__' + (counter++) + '__';
}
return a.toString();
};
}
},
getType: function(path) {
var array, step, value, _i, _len;
array = isArray(path) ? path: path.split('.');
value = global;
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
if (!isFunction(value)) {
throw new Error("Type not found: " + path);
}
return value;
},
test: {
values: function() {
return assertEquals(values({
a: 1,
b: 3,
c: 2
}), [1, 3, 2]);
},
patch: function() {
var x;
x = {
a: {
foo: 1,
bar: 3
},
b: 2
};
patch(x, 'a', 'foo', 5);
return assertEquals(x.a.foo, 5);
}
},
name: "glass",
path: "glass",
namespace: ""
}
},
String: {
source: "extension: true
properties:
\tstartsWith: (s) -> @slice(0,s.length) is s
\tendsWith: (s) -> @slice(-s.length) is s
\tcontains: (s) -> @indexOf(s) >= 0
\ttoArray: () -> @split ''",
input: "runtime\\String.coffee",
content: {
extension: true,
properties: {
startsWith: function(s) {
return this.slice(0, s.length) === s;
},
endsWith: function(s) {
return this.slice( - s.length) === s;
},
contains: function(s) {
return this.indexOf(s) >= 0;
},
toArray: function() {
return this.split('');
}
},
name: "String",
path: "String",
namespace: ""
}
}
}
} | {
options: {
input: {
dir: "runtime",
match: /\.(coffee|pegjs)$/
},
output: {
dir: "www/js"
},
script: {
includes: "www/includes.html",
prefix: "/js/"
},
module: {
main: "glass.js",
prefix: "./www/js/"
},
debug: "buildlog.html",
test: "glass.allTests",
addon: {
pregenerate: {
addUri: function(schema) {
var content, type, typeName, _ref2, _ref3;
_ref2 = schema.types;
for (typeName in _ref2) {
type = _ref2[typeName];
content = type.content;
if (content.extension) {
continue;
}
if ((_ref3 = content.uri) == null) {
content.uri = "global:/" + (content.path.replace(/\./g, '/'));
}
}
return schema;
}
}
},
namespace: ""
},
types: {
"glass.Component": {
source: "extends: 'Observable'
constructor: (properties) ->
@patch properties
# now site ourselves on our parent
if @parent
id = getId @
patch @parent, id, @
@
properties:
id:
description: 'string which uniquely identifies this component within its parent'
type: 'string'
parent:
description: 'the object that contains this component'
serializable: false
type: 'object'
disposed: false
dispose: -> @patch 'disposed', true
notify: (change) ->
Observable.prototype.notify.apply this, arguments
if change?.disposed
# dispose of any disposable children
for id, child of @ when child?.parent is @
child.dispose?()
# remove self from parent
if @id and @parent
patch @parent, @id, undefined
return
test:
lifecycle: ->
parent = new Component
assert not parent.id?
assert not parent.parent?
child = new Component parent:parent
# id should be automatically assigned
assert isString child.id
assert parent is child.parent
assert parent[child.id] is child
assert parent.hasOwnProperty child.id
parent.dispose()
assert child.disposed is true
assert not parent.hasOwnProperty child.id
nonEnumerability: ->
visibleKeys = (key for key of new Component)
assertEquals visibleKeys, []",
input: "runtime\\glass\\Component.coffee",
content: {
extends: "Observable",
constructor: function(properties) {
var id;
this.patch(properties);
if (this.parent) {
id = getId(this);
patch(this.parent, id, this);
}
return this;
},
properties: {
id: {
description: "string which uniquely identifies this component within its parent",
type: "string"
},
parent: {
description: "the object that contains this component",
serializable: false,
type: "object"
},
disposed: false,
dispose: function() {
return this.patch('disposed', true);
},
notify: function(change) {
var child, id;
Observable.prototype.notify.apply(this, arguments);
if (change != null ? change.disposed: void 0) {
for (id in this) {
child = this[id];
if ((child != null ? child.parent: void 0) === this) {
if (typeof child.dispose === "function") {
child.dispose();
}
}
}
if (this.id && this.parent) {
patch(this.parent, this.id, void 0);
}
}
}
},
test: {
lifecycle: function() {
var child, parent;
parent = new Component;
assert(!(parent.id != null));
assert(!(parent.parent != null));
child = new Component({
parent: parent
});
assert(isString(child.id));
assert(parent === child.parent);
assert(parent[child.id] === child);
assert(parent.hasOwnProperty(child.id));
parent.dispose();
assert(child.disposed === true);
return assert(!parent.hasOwnProperty(child.id));
},
nonEnumerability: function() {
var key, visibleKeys;
visibleKeys = (function() {
var _results;
_results = [];
for (key in new Component) {
_results.push(key);
}
return _results;
})();
return assertEquals(visibleKeys, []);
}
},
name: "Component",
path: "glass.Component",
namespace: "glass"
}
},
"glass.Container": {
source: "extends: 'Observable'
properties:
watch: ->
unwatch: ->
",
input: "runtime\\glass\\Container.coffee",
content: {
extends: "Observable",
properties: {
watch: function() {},
unwatch: function() {}
},
name: "Container",
path: "glass.Container",
namespace: "glass"
}
},
"glass.Expression._parser": {
source: "{
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e,array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++)
array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
}
start = expression
expression = conditional
conditional = e:or args:(\"?\" b:expression \":\" c:expression {return [b,c];})* {
while (args.length > 0) {
e = expr(\"?:\", [e].concat(args.pop()));
}
return e;
}
or = a:and b:((\"or\") and)* { return joinLeft(a,b); }
and = a:equality b:((\"and\") equality)* { return joinLeft(a,b); }
equality = a:rel b:((\"==\" / \"!=\") rel)* { return joinLeft(a,b); }
rel = a:sum b:((\"<=\" / \">=\" / \"<\" / \">\") sum)* { return joinLeft(a,b); }
sum = a:product b:((\"+\" / \"-\") product)* { return joinLeft(a,b); }
product = a:not b:((\"*\" / \"div\" / \"mod\") not)* { return joinLeft(a,b); }
not = ops:(s op:(\"!\" / \"~\" / \"+\" / \"-\") { return op; })* b:primary { return unaryRight(ops,b); }
primary = s a:(group / literal / path) s { return a; }
group = \"(\" a:expression \")\" { return a; }
literal = s a:(boolean / number / string / array / object) s { return a; }
boolean = a:(\"true\" / \"false\") { return a == \"true\"; }
number = a:([0-9]+ (\".\" [0-9]+)?) { return parseFloat(toString(a)); }
hex = [a-fA-F0-9]
// as per JSON http://www.json.org
string = a:( '\"' (
[\\u0000-\\u0021\\u0023-\\u005c\\u005e-\\uffff] // all unicode chars except \\ and \"
/ (\"\\\\\" (\"\\\"\" / \"\\\\\" / \"\\/\" / \"b\" / \"f\" / \"n\" / \"r\" / \"t\" / (\"u\" hex hex hex hex)))
)* '\"' )
{ return JSON.parse(toString(a)); }
array = \"[\" a:values \"]\" { return expr(\"array\", a); }
values = first:expression? args:(\",\" b:expression {return b;})* {
if (first != \"\") { args.unshift(first); } return args;
}
object = \"{\" a:keyvalues \"}\" { return expr(\"object\", a); }
keyvalue = s a:string s \":\" b:expression { return [a,b]; }
keyvalues = first:keyvalue? rest:(\",\" b:keyvalue {return b;})* {
if (first) { rest.unshift(first); } return rest;
}
ref = a:(\"//\" / \"/\" / \"$\" / \"**\" / \"*\" / \"..\" / \".\") b:slashProperty? {
e = expr(a); if (b) { b.args.unshift(e); e = b; } return e;
}
/ a:id { return expr(\"ref\", [a]); }
id = a:[a-z_]+ b:[a-z_0-9]* { return a.join('') + b.join(''); }
property = \"/\" a:slashProperty { return a; }
/ \"{\" a:expression \"}\" { return expr(\"{}\", [a]); } // locally scoped expression
/ \"[\" a:expression \"]\" { return expr(\"[]\", [a]); } // predicate
slashProperty = a:(id/number/string) { return expr(\"/\", [a]); }
/ a:(\"..\" / \"*\") { return expr(a, []); }
s \"space\" = [ ]* { return ''; }
path = a:root b:step* {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
}
root = a:implicitDotRoot b:dotStep? { return joinPath(a,b); }
/ explicitDotRoot
step = \".\" a:dotStep { return a; }
/ noDotStep
implicitDotRoot = \"/\" { return expr(\"root\"); }
/ \"@\" { return expr(\"this\"); }
/ \".\" a:\".\"+ { return expr(\"ancestor\", [a.length]); }
explicitDotRoot = a:id { return expr(\"ref\", [a]); }
/ \"*\" { return expr(\"values\", []); }
dotStep = a:(id / string / number) { return expr(\"get\", [a]); }
/ \"*\" { return expr(\"values\", []); }
noDotStep = \"{\" a:expression \"}\" { return expr(\"eval\", [a]); }
/ \"[\" a:expression \"]\" { return expr(\"pred\", [a]); }
/ \"(\" a:values \")\" { return expr(\"call\", [a]); }
",
input: "runtime\\glass\\Expression\\_parser.pegjs",
content: {
value: {
parse: function(input, startRule) {
var parseFunctions = {
"conditional": parse_conditional,
"or": parse_or,
"and": parse_and,
"equality": parse_equality,
"rel": parse_rel,
"sum": parse_sum,
"product": parse_product,
"not": parse_not,
"primary": parse_primary,
"group": parse_group,
"literal": parse_literal,
"boolean": parse_boolean,
"number": parse_number,
"hex": parse_hex,
"string": parse_string,
"array": parse_array,
"values": parse_values,
"object": parse_object,
"keyvalue": parse_keyvalue,
"keyvalues": parse_keyvalues,
"ref": parse_ref,
"id": parse_id,
"property": parse_property,
"slashProperty": parse_slashProperty,
"s": parse_s,
"path": parse_path,
"root": parse_root,
"step": parse_step,
"implicitDotRoot": parse_implicitDotRoot,
"explicitDotRoot": parse_explicitDotRoot,
"dotStep": parse_dotStep,
"noDotStep": parse_noDotStep
};
if (startRule !== undefined) {
if (parseFunctions[startRule] === undefined) {
throw new Error("Invalid rule name: " + quote(startRule) + ".");
}
} else {
startRule = "conditional";
}
var pos = 0;
var reportFailures = 0;
var rightmostFailuresPos = 0;
var rightmostFailuresExpected = [];
function padLeft(input, padding, length) {
var result = input;
var padLength = length - input.length;
for (var i = 0; i < padLength; i++) {
result = padding + result;
}
return result;
}
function escape(ch) {
var charCode = ch.charCodeAt(0);
var escapeChar;
var length;
if (charCode <= 0xFF) {
escapeChar = 'x';
length = 2;
} else {
escapeChar = 'u';
length = 4;
}
return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
}
function matchFailed(failure) {
if (pos < rightmostFailuresPos) {
return;
}
if (pos > rightmostFailuresPos) {
rightmostFailuresPos = pos;
rightmostFailuresExpected = [];
}
rightmostFailuresExpected.push(failure);
}
function parse_conditional() {
var result0, result1, result2, result3, result4, result5;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_or();
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, e, args) {
while (args.length > 0) {
e = expr("?:", [e].concat(args.pop()));
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_or() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_and();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_and() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_equality();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_equality() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_rel();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_rel() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_sum();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_sum() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_product();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_product() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_not();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_not() {
var result0, result1, result2;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = [];
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
while (result1 !== null) {
result0.push(result1);
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
}
if (result0 !== null) {
result1 = parse_primary();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, ops, b) {
return unaryRight(ops, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_primary() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_group();
if (result1 === null) {
result1 = parse_literal();
if (result1 === null) {
result1 = parse_path();
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_group() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_literal() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_boolean();
if (result1 === null) {
result1 = parse_number();
if (result1 === null) {
result1 = parse_string();
if (result1 === null) {
result1 = parse_array();
if (result1 === null) {
result1 = parse_object();
}
}
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_boolean() {
var result0;
var pos0;
pos0 = pos;
if (input.substr(pos, 4) === "true") {
result0 = "true";
pos += 4;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"true\"");
}
}
if (result0 === null) {
if (input.substr(pos, 5) === "false") {
result0 = "false";
pos += 5;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"false\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a == "true";
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_number() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
pos2 = pos;
if (input.charCodeAt(pos) === 46) {
result1 = ".";
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result1 !== null) {
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result3 !== null) {
result2 = [];
while (result3 !== null) {
result2.push(result3);
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result2 = null;
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos2;
}
} else {
result1 = null;
pos = pos2;
}
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return parseFloat(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_hex() {
var result0;
if (/^[a-fA-F0-9]/.test(input.charAt(pos))) {
result0 = input.charAt(pos);
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("[a-fA-F0-9]");
}
}
return result0;
}
function parse_string() {
var result0, result1, result2, result3, result4, result5, result6, result7;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 34) {
result0 = "\"";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result0 !== null) {
result1 = [];
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
}
if (result1 !== null) {
if (input.charCodeAt(pos) === 34) {
result2 = "\"";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return JSON.parse(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_array() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("array", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_values() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_conditional();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, args) {
if (first != "") {
args.unshift(first);
}
return args;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_object() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_keyvalues();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("object", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalue() {
var result0, result1, result2, result3, result4;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_string();
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
if (input.charCodeAt(pos) === 58) {
result3 = ":";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result3 !== null) {
result4 = parse_conditional();
if (result4 !== null) {
result0 = [result0, result1, result2, result3, result4];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return [a, b];
})(pos0, result0[1], result0[4]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalues() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_keyvalue();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, rest) {
if (first) {
rest.unshift(first);
}
return rest;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_ref() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.substr(pos, 2) === "//") {
result0 = "//";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"//\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 36) {
result0 = "$";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"$\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "**") {
result0 = "**";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"**\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
}
}
}
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
e = expr(a);
if (b) {
b.args.unshift(e);
e = b;
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_id() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
result1 = [];
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return a.join('') + b.join('');
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_property() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("{}", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("[]", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_slashProperty() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_number();
if (result0 === null) {
result0 = parse_string();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("/", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(a, []);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_s() {
var result0, result1;
var pos0;
reportFailures++;
pos0 = pos;
result0 = [];
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
while (result1 !== null) {
result0.push(result1);
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
}
if (result0 !== null) {
result0 = (function(offset) {
return '';
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
reportFailures--;
if (reportFailures === 0 && result0 === null) {
matchFailed("space");
}
return result0;
}
function parse_path() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_root();
if (result0 !== null) {
result1 = [];
result2 = parse_step();
while (result2 !== null) {
result1.push(result2);
result2 = parse_step();
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_root() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_implicitDotRoot();
if (result0 !== null) {
result1 = parse_dotStep();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinPath(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_explicitDotRoot();
}
return result0;
}
function parse_step() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
result1 = parse_dotStep();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_noDotStep();
}
return result0;
}
function parse_implicitDotRoot() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("root");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 64) {
result0 = "@";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"@\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("this");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result2 !== null) {
result1 = [];
while (result2 !== null) {
result1.push(result2);
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
} else {
result1 = null;
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ancestor", [a.length]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_explicitDotRoot() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_dotStep() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_string();
if (result0 === null) {
result0 = parse_number();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("get", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_noDotStep() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("eval", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("pred", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("call", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function cleanupExpected(expected) {
expected.sort();
var lastExpected = null;
var cleanExpected = [];
for (var i = 0; i < expected.length; i++) {
if (expected[i] !== lastExpected) {
cleanExpected.push(expected[i]);
lastExpected = expected[i];
}
}
return cleanExpected;
}
function computeErrorPosition() {
/*
* The first idea was to use |String.split| to break the input up to the
* error position along newlines and derive the line and column from
* there. However IE's |split| implementation is so broken that it was
* enough to prevent it.
*/
var line = 1;
var column = 1;
var seenCR = false;
for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
var ch = input.charAt(i);
if (ch === "
") {
if (!seenCR) {
line++;
}
column = 1;
seenCR = false;
} else if (ch === "
" || ch === "\u2028" || ch === "\u2029") {
line++;
column = 1;
seenCR = true;
} else {
column++;
seenCR = false;
}
}
return {
line: line,
column: column
};
}
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e, array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++) array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
var result = parseFunctions[startRule]();
/*
* The parser is now in one of the following three states:
*
* 1. The parser successfully parsed the whole input.
*
* - |result !== null|
* - |pos === input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 2. The parser successfully parsed only a part of the input.
*
* - |result !== null|
* - |pos < input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 3. The parser did not successfully parse any part of the input.
*
* - |result === null|
* - |pos === 0|
* - |rightmostFailuresExpected| contains at least one failure
*
* All code following this comment (including called functions) must
* handle these states.
*/
if (result === null || pos !== input.length) {
var offset = Math.max(pos, rightmostFailuresPos);
var found = offset < input.length ? input.charAt(offset) : null;
var errorPosition = computeErrorPosition();
throw new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column);
}
return result;
},
toSource: function() {
return this._source;
},
SyntaxError: function(expected, found, offset, line, column) {
function buildMessage(expected, found) {
var expectedHumanized, foundHumanized;
switch (expected.length) {
case 0:
expectedHumanized = "end of input";
break;
case 1:
expectedHumanized = expected[0];
break;
default:
expectedHumanized = expected.slice(0, expected.length - 1).join(", ") + " or " + expected[expected.length - 1];
}
foundHumanized = found ? quote(found) : "end of input";
return "Expected " + expectedHumanized + " but " + foundHumanized + " found.";
}
this.name = "SyntaxError";
this.expected = expected;
this.found = found;
this.message = buildMessage(expected, found);
this.offset = offset;
this.line = line;
this.column = column;
}
},
name: "_parser",
path: "glass.Expression._parser",
namespace: "glass.Expression"
}
},
"glass.Expression": {
source: "constructor: (op, args) ->
@op = op
@args = args if args?
@
properties:
op:
type: 'string'
args:
type: 'array'
test: ->
return
peg = require 'pegjs'
fs = require 'fs'
parserSource = fs.readFileSync 'runtime/glass/Expression/_parser.pegjs', 'utf8'
parser = peg.buildParser parserSource
tests =
\"a.b.c\": {op:\"get\",args:[{op:\"get\",args:[{op:\"ref\",args:[\"a\"]},\"b\"]},\"c\"]}
\"a.1\": {op:\"get\",args:[{op:\"ref\",args:[\"a\"]},1]}
\"true\": true
\"false\": false
\"45.8\": 45.8
\"(45.8)\": 45.8
\"((45.8))\": 45.8
\"alpha\": {op:\"ref\",args:[\"alpha\"]}
\"35 + true * 2\": {op:\"+\", args:[35, {op:\"*\", args:[true,2]}]}
\" 5 * ( 2 + 2 ) \": {op:\"*\", args:[5, {op:\"+\", args:[2,2]}]}
\" ! ! true\": {op:\"!\",args:[{op:\"!\",args:[true]}]}
\"5 + -x\": {op:\"+\",args:[5,{op:\"-\",args:[{op:\"ref\",args:[\"x\"]}]}]}
\"true == 5 >= 2\": {op:\"==\",args:[true,{op:\">=\",args:[5,2]}]}
\"1 or 2 and 3\": {op:\"or\",args:[1,{op:\"and\",args:[2,3]}]}
\"1 ? 2 : 3\": {op:\"?:\",args:[1,2,3]}
\"1 ? 2 : 3 ? 4 : 5\" : {op:\"?:\",args:[1,2,{op:\"?:\",args:[3,4,5]}]}
\"a()(1,2)\" : {op:\"call\",args:[{op:\"call\",args:[{op:\"ref\",args:[\"a\"]},[]]},[1,2]]}
\"@\" : {op:\"this\"}
\"@foo\" : {op:\"get\",args:[{op:\"this\"},\"foo\"]}
'\"hello\"': \"hello\"
'\"\\\\t\\
\\
\\\\b\\\\\\\\foo\\\\\\/\"' : \"\\t
\\b\\\\foo\\/\"
\"[]\": {op:\"array\",args:[]}
\"[1,2]\": {op:\"array\",args:[1,2]}
\"[1+2]\": {op:\"array\",args:[{op:\"+\",args:[1,2]}]}
\"{}\": {op:\"object\",args:[]}
'{\"a\":2}': {op:\"object\",args:[[\"a\",2]]}
'{\"a\":2,\"b\":1+2}': {op:\"object\",args:[[\"a\",2],[\"b\",{op:\"+\",args:[1,2]}]]}
'@\"alpha\"': {op:\"get\",args:[{op:\"this\"},\"alpha\"]}
'*': {op:\"values\",args:[]}
'*.*': {op:\"values\",args:[{op:\"values\",args:[]}]}
\"foo.*\": {op:\"values\",args:[{op:\"ref\",args:[\"foo\"]}]}
\"..\": {op:\"ancestor\",args:[1]}
\"...\": {op:\"ancestor\",args:[2]}
\"@*{1+2}\": {op:\"eval\",args:[{op:\"values\",args:[{op:\"this\"}]},{op:\"+\",args:[1,2]}]}
\"/\": {op:\"root\"}
\"/foo\": {op:\"get\",args:[{op:\"root\"},\"foo\"]}
\"/*\": {op:\"values\",args:[{op:\"root\"}]}
for text, expected of tests
result = parser.parse text
if JSON.stringify(result) is JSON.stringify(expected)
console.log 'Pass: ' + text
else
console.log text, JSON.stringify result
return
",
input: "runtime\\glass\\Expression.coffee",
content: {
constructor: function(op, args) {
this.op = op;
if (args != null) {
this.args = args;
}
return this;
},
properties: {
op: {
type: "string"
},
args: {
type: "array"
}
},
test: function() {
var expected, fs, parser, parserSource, peg, result, tests, text;
return;
peg = require('pegjs');
fs = require('fs');
parserSource = fs.readFileSync('runtime/glass/Expression/_parser.pegjs', 'utf8');
parser = peg.buildParser(parserSource);
tests = {
"a.b.c": {
op: "get",
args: [{
op: "get",
args: [{
op: "ref",
args: ["a"]
},
"b"]
},
"c"]
},
"a.1": {
op: "get",
args: [{
op: "ref",
args: ["a"]
},
1]
},
"true": true,
"false": false,
"45.8": 45.8,
"(45.8)": 45.8,
"((45.8))": 45.8,
"alpha": {
op: "ref",
args: ["alpha"]
},
"35 + true * 2": {
op: "+",
args: [35, {
op: "*",
args: [true, 2]
}]
},
" 5 * ( 2 + 2 ) ": {
op: "*",
args: [5, {
op: "+",
args: [2, 2]
}]
},
" ! ! true": {
op: "!",
args: [{
op: "!",
args: [true]
}]
},
"5 + -x": {
op: "+",
args: [5, {
op: "-",
args: [{
op: "ref",
args: ["x"]
}]
}]
},
"true == 5 >= 2": {
op: "==",
args: [true, {
op: ">=",
args: [5, 2]
}]
},
"1 or 2 and 3": {
op: "or",
args: [1, {
op: "and",
args: [2, 3]
}]
},
"1 ? 2 : 3": {
op: "?:",
args: [1, 2, 3]
},
"1 ? 2 : 3 ? 4 : 5": {
op: "?:",
args: [1, 2, {
op: "?:",
args: [3, 4, 5]
}]
},
"a()(1,2)": {
op: "call",
args: [{
op: "call",
args: [{
op: "ref",
args: ["a"]
},
[]]
},
[1, 2]]
},
"@": {
op: "this"
},
"@foo": {
op: "get",
args: [{
op: "this"
},
"foo"]
},
'"hello"': "hello",
'"\\t
\\b\\\\foo\\\/"': "\t
\b\\foo\/",
"[]": {
op: "array",
args: []
},
"[1,2]": {
op: "array",
args: [1, 2]
},
"[1+2]": {
op: "array",
args: [{
op: "+",
args: [1, 2]
}]
},
"{}": {
op: "object",
args: []
},
'{"a":2}': {
op: "object",
args: [["a", 2]]
},
'{"a":2,"b":1+2}': {
op: "object",
args: [["a", 2], ["b", {
op: "+",
args: [1, 2]
}]]
},
'@"alpha"': {
op: "get",
args: [{
op: "this"
},
"alpha"]
},
'*': {
op: "values",
args: []
},
'*.*': {
op: "values",
args: [{
op: "values",
args: []
}]
},
"foo.*": {
op: "values",
args: [{
op: "ref",
args: ["foo"]
}]
},
"..": {
op: "ancestor",
args: [1]
},
"...": {
op: "ancestor",
args: [2]
},
"@*{1+2}": {
op: "eval",
args: [{
op: "values",
args: [{
op: "this"
}]
},
{
op: "+",
args: [1, 2]
}]
},
"/": {
op: "root"
},
"/foo": {
op: "get",
args: [{
op: "root"
},
"foo"]
},
"/*": {
op: "values",
args: [{
op: "root"
}]
}
};
for (text in tests) {
expected = tests[text];
result = parser.parse(text);
if (JSON.stringify(result) === JSON.stringify(expected)) {
console.log('Pass: ' + text);
} else {
console.log(text, JSON.stringify(result));
}
}
},
name: "Expression",
path: "glass.Expression",
namespace: "glass"
}
},
"glass.JSONMergePatch": {
source: "
# applies a patch to the target object and returns the resulting target
apply: (target, patch) ->
if target? and target isnt patch and isPlainObject(patch) and not isPrimitive(target)
for key, value of patch
if value is undefined
delete target[key]
else
target[key] = apply target[key], patch[key]
return target
else
return patch
# (path1, path2, path3.., patch) ->
create: ->
if arguments.length is 1
return arguments[0]
result = {}
current = result
for arg, i in arguments when i + 1 < arguments.length
last = i + 2 is arguments.length
current = current[arg] = if last then arguments[arguments.length-1] else {}
result
test: ->
assertEquals {a:{b:12}}, create 'a', 'b', 12
assertEquals {a:3}, apply({a:1,b:2}, {a:3,b:undefined})
",
input: "runtime\\glass\\JSONMergePatch.coffee",
content: {
apply: function(target, patch) {
var key, value;
if ((target != null) && target !== patch && isPlainObject(patch) && !isPrimitive(target)) {
for (key in patch) {
value = patch[key];
if (value === void 0) {
delete target[key];
} else {
target[key] = apply(target[key], patch[key]);
}
}
return target;
} else {
return patch;
}
},
create: function() {
var arg, current, i, last, result, _i, _len;
if (arguments.length === 1) {
return arguments[0];
}
result = {};
current = result;
for (i = _i = 0, _len = arguments.length; _i < _len; i = ++_i) {
arg = arguments[i];
if (! (i + 1 < arguments.length)) {
continue;
}
last = i + 2 === arguments.length;
current = current[arg] = last ? arguments[arguments.length - 1] : {};
}
return result;
},
test: function() {
assertEquals({
a: {
b: 12
}
},
create('a', 'b', 12));
return assertEquals({
a: 3
},
apply({
a: 1,
b: 2
},
{
a: 3,
b: void 0
}));
},
name: "JSONMergePatch",
path: "glass.JSONMergePatch",
namespace: "glass"
}
},
"glass.JSONPointer": {
source: "# json pointer implementation as per
# http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-05
_decodeStep: (step) -> step.replace(/~1/g, '/').replace(/~0/g, '~')
_getLastStep: (pointer) ->
_decodeStep pointer.substring(pointer.lastIndexOf('/') + 1)
_getParent: (pointer) ->
if not pointer?.length
null
else
pointer.substring(0, pointer.lastIndexOf('/'))
toArray: (pointer) ->
for step in pointer.substring(1).split('/')
_decodeStep step
get: (doc, pointer) ->
value = doc
if pointer.length
path = toArray pointer
for step in path when value?
value = value[step]
value
set: (doc, pointer, value) ->
parentPointer = _getParent pointer
if parentPointer?
parent = get doc, parentPointer
lastStep = _getLastStep pointer
parent[lastStep] = value
value
test: ->
assertEquals _getParent(\"/a/b/c\"), \"/a/b\"
assertEquals _getParent(\"/a\"), \"\"
assertEquals _getParent(\"\"), null
assertEquals _getLastStep(\"/a/b/c\"), \"c\"
assertEquals _getLastStep(\"/a~0~1\"), \"a~/\"
assertEquals _getLastStep(\"\"), \"\"
# tests as per spec
doc = {
\"foo\": [\"bar\", \"baz\"],
\"\": 0,
\"a/b\": 1,
\"c%d\": 2,
\"e^f\": 3,
\"g|h\": 4,
\"i\\\\j\": 5,
\"k\\\"l\": 6,
\" \": 7,
\"m~n\": 8
}
assertEquals get(doc, \"\"), doc
assertEquals get(doc, \"/foo\"), [\"bar\", \"baz\"]
assertEquals get(doc, \"/foo/0\"), \"bar\"
assertEquals get(doc, \"/\"), 0
assertEquals get(doc, \"/a~1b\"), 1
assertEquals get(doc, \"/c%d\"), 2
assertEquals get(doc, \"/e^f\"), 3
assertEquals get(doc, \"/g|h\"), 4
assertEquals get(doc, \"/i\\\\j\"), 5
assertEquals get(doc, \"/k\\\"l\"), 6
assertEquals get(doc, \"/ \"), 7
assertEquals get(doc, \"/m~0n\"), 8
# now test set
assertEquals set(doc, \"/\", 10), 10
assertEquals doc[\"\"], 10
assertEquals set(doc, \"/foo/0\", 10), 10
assertEquals doc.foo[0], 10",
input: "runtime\\glass\\JSONPointer.coffee",
content: {
toArray: function(pointer) {
var step, _i, _len, _ref, _results;
_ref = pointer.substring(1).split('/');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
step = _ref[_i];
_results.push(_decodeStep(step));
}
return _results;
},
get: function(doc, pointer) {
var path, step, value, _i, _len;
value = doc;
if (pointer.length) {
path = toArray(pointer);
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
}
return value;
},
set: function(doc, pointer, value) {
var lastStep, parent, parentPointer;
parentPointer = _getParent(pointer);
if (parentPointer != null) {
parent = get(doc, parentPointer);
lastStep = _getLastStep(pointer);
parent[lastStep] = value;
}
return value;
},
test: function() {
var doc;
assertEquals(_getParent("/a/b/c"), "/a/b");
assertEquals(_getParent("/a"), "");
assertEquals(_getParent(""), null);
assertEquals(_getLastStep("/a/b/c"), "c");
assertEquals(_getLastStep("/a~0~1"), "a~/");
assertEquals(_getLastStep(""), "");
doc = {
"foo": ["bar", "baz"],
"": 0,
"a/b": 1,
"c%d": 2,
"e^f": 3,
"g|h": 4,
"i\\j": 5,
"k\"l": 6,
" ": 7,
"m~n": 8
};
assertEquals(get(doc, ""), doc);
assertEquals(get(doc, "/foo"), ["bar", "baz"]);
assertEquals(get(doc, "/foo/0"), "bar");
assertEquals(get(doc, "/"), 0);
assertEquals(get(doc, "/a~1b"), 1);
assertEquals(get(doc, "/c%d"), 2);
assertEquals(get(doc, "/e^f"), 3);
assertEquals(get(doc, "/g|h"), 4);
assertEquals(get(doc, "/i\\j"), 5);
assertEquals(get(doc, "/k\"l"), 6);
assertEquals(get(doc, "/ "), 7);
assertEquals(get(doc, "/m~0n"), 8);
assertEquals(set(doc, "/", 10), 10);
assertEquals(doc[""], 10);
assertEquals(set(doc, "/foo/0", 10), 10);
return assertEquals(doc.foo[0], 10);
},
name: "JSONPointer",
path: "glass.JSONPointer",
namespace: "glass"
}
},
"glass.Observable": {
source: "properties:
is: (type) -> @constructor.implements[type.path ? type] is true
watchers:
serializable: false
watch: (property, watcher) ->
if isFunction property
watcher = property
property = ''
id = getId watcher
@patch 'watchers', property, id, watcher
# returns a function which will remove the watch
=> @patch 'watchers', property, getId(watcher), undefined
patch: (change) ->
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
try
JSONMergePatch.apply this, change
catch e
console.log e
finally
@notify change
return
notify: (change) ->
if @watchers?
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
for property, watchers of @watchers
if property.length is 0 or change.hasOwnProperty property
changeArg = if property.length is 0 then change else change[property]
for id, watcher of watchers
watcher this, changeArg
return
toJSON: ->
values =
class: @constructor.path
# serialize statically defined properties
for name, property of @constructor.properties
value = @[name]
if property.serializable isnt false and not isFunction(value)
values[name] = value
# serialize custom properties if allowed by schema
if @constructor.additionalProperties isnt false
for own name, value of @ when not isPrivate name
values[name] = value
values
toString: -> @toJSON()
test:
toJSON: ->
# I need this test later
# on a class that actually has serializable properties
a = new Observable
a.x = 12
a.y = ->
a.z = true
assertEquals a, {class:'glass.Observable', x:12,z:true}
watchAll: ->
# we should actually be able to watch ourselves get added to watchers
# this is very meta.
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch watcher
# now make sure we were called with our own watcher
assert watchArgs[0] is a
assert watchArgs[1]?.watchers?[\"\"]?
# reset watchArgs, and watch something else
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assertEquals a.a, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {a:{b:3}}
# now unwatch
unwatch()
# make sure universal watcher is now empty
assertEquals a.watchers[\"\"], {}
# now reset and do a new event, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
watchProperty: ->
# watch a property
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch \"foo\", watcher
# now make sure we were not called
assert watchArgs.length is 0
# reset watchArgs, and watch something else
a.patch \"foo\", \"b\", 3
assertEquals a.foo, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {b:3}
# now reset and do a different property, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
# now unwatch
unwatch()
# make sure we no longer see foo
watchArgs.length = 0
a.patch \"foo\", \"b\", 4
assert watchArgs.length is 0
",
input: "runtime\\glass\\Observable.coffee",
content: {
properties: {
is: function(type) {
var _ref;
return this.constructor["implements"][(_ref = type.path) != null ? _ref: type] === true;
},
watchers: {
serializable: false
},
watch: function(property, watcher) {
var id, _this = this;
if (isFunction(property)) {
watcher = property;
property = '';
}
id = getId(watcher);
this.patch('watchers', property, id, watcher);
return function() {
return _this.patch('watchers', property, getId(watcher), void 0);
};
},
patch: function(change) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
try {
JSONMergePatch.apply(this, change);
} catch(e) {
console.log(e);
} finally {
this.notify(change);
}
},
notify: function(change) {
var changeArg, id, property, watcher, watchers, _ref;
if (this.watchers != null) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
_ref = this.watchers;
for (property in _ref) {
watchers = _ref[property];
if (property.length === 0 || change.hasOwnProperty(property)) {
changeArg = property.length === 0 ? change: change[property];
for (id in watchers) {
watcher = watchers[id];
watcher(this, changeArg);
}
}
}
}
},
toJSON: function() {
var name, property, value, values, _ref;
values = {
"class": this.constructor.path
};
_ref = this.constructor.properties;
for (name in _ref) {
property = _ref[name];
value = this[name];
if (property.serializable !== false && !isFunction(value)) {
values[name] = value;
}
}
if (this.constructor.additionalProperties !== false) {
for (name in this) {
if (!__hasProp.call(this, name)) continue;
value = this[name];
if (!isPrivate(name)) {
values[name] = value;
}
}
}
return values;
},
toString: function() {
return this.toJSON();
}
},
test: {
toJSON: function() {
var a;
a = new Observable;
a.x = 12;
a.y = function() {};
a.z = true;
return assertEquals(a, {
"class": 'glass.Observable',
x: 12,
z: true
});
},
watchAll: function() {
var a, unwatch, watchArgs, watcher, _ref, _ref1;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch(watcher);
assert(watchArgs[0] === a);
assert(((_ref = watchArgs[1]) != null ? (_ref1 = _ref.watchers) != null ? _ref1[""] : void 0 : void 0) != null);
watchArgs.length = 0;
a.patch("a", "b", 3);
assertEquals(a.a, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
a: {
b: 3
}
});
unwatch();
assertEquals(a.watchers[""], {});
watchArgs.length = 0;
a.patch("a", "b", 3);
return assert(watchArgs.length === 0);
},
watchProperty: function() {
var a, unwatch, watchArgs, watcher;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch("foo", watcher);
assert(watchArgs.length === 0);
a.patch("foo", "b", 3);
assertEquals(a.foo, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
b: 3
});
watchArgs.length = 0;
a.patch("a", "b", 3);
assert(watchArgs.length === 0);
unwatch();
watchArgs.length = 0;
a.patch("foo", "b", 4);
return assert(watchArgs.length === 0);
}
},
name: "Observable",
path: "glass.Observable",
namespace: "glass"
}
},
glass: {
source: "require:
\tString: true
# runtime type tests
isFunction: (object) -> object? and typeof object is 'function'
isString: (object) -> object?.constructor is String
isArray: (object) -> Array.isArray object
isBoolean: (object) -> object? and typeof object is 'boolean'
isNumber: (object) -> object? and typeof object is 'number'
isObject: (object) -> typeof object is 'object'
isPlainObject: (object) -> object?.constructor is Object
isPrototype: (object) -> object? and object is object.constructor.prototype
isDate: (object) -> object?.constructor is Date
isPrimitive: (object) -> isString(object) or isBoolean(object) or isNumber(object) or isDate(object)
isPrivate: (property) -> property?[0] is '_'
# generic utility functions
values: (object) -> (value for key, value of object)
# generic patch method, uses patch method built into object if present
patch: (target, pathAndPatch...) ->
patch = JSONMergePatch.create.apply null, pathAndPatch
if isFunction target?.patch
target.patch patch
else
glass.JSONMergePatch.apply target, patch
# testing assertions
_getStackLocationInfo: (e, depth) ->
line = e.stack?.split('
')[depth]
return null unless line?
match = /\\(([\\w\\W]*?):(\\d+):(\\d+)\\)/.exec line
return {
file: match[1]
line: parseInt match[2]
column: parseInt match[3]
}
_throwAssertionFailure: (message) ->
try
throw new Error \"Assertion failed: \" + message
catch e
info = _getStackLocationInfo e, 3
if info?
_dumpFile info.file, info.line - 2, info.line + 2, info.line
throw e
_dumpFile: (file, from=1, to, highlight) ->
fs = require 'fs'
return unless fs?
try
content = fs.readFileSync(file).toString()
catch e
content = \"Source not found: #{e}\"
console.log '------------------------------------------------'
console.log file
console.log '------------------------------------------------'
number = 1
if content?
lines = content.split /
|
/
to ?= lines.length
for line in lines
lineNumber = number++
if lineNumber >= from and lineNumber <= to
num = String lineNumber
while num.length < 3
num += ' '
if lineNumber is highlight
`console.log(\"\\033[91m\" + num + \": \" + line + \"\\033[0m\");`
else
`console.log(num + \": \" + line);`
console.log '------------------------------------------------'
assert: (a) ->
_throwAssertionFailure JSON.stringify(a) unless a
assertTrue: (a) ->
_throwAssertionFailure JSON.stringify(a) + \" != true\" unless a is true
assertEquals: (a, b) ->
if JSON.stringify(a) isnt JSON.stringify(b)
_throwAssertionFailure JSON.stringify(a) + ' != ' + JSON.stringify(b)
# gets a unique string identifier for any object
getId:
do: ->
counter = 0
(a) ->
if a is null
return '__null__'
if a is undefined
return '__undefined__'
if typeof a is 'object' or typeof a is 'function'
return a.id ?= '__' + (counter++) + '__'
# 12 == \"12\" under this technique
return a.toString()
getType: (path) ->
array = if isArray path then path else path.split '.'
value = global
for step in path when value?
value = value[step]
throw new Error \"Type not found: #{path}\" unless isFunction value
value
test:
values: ->
assertEquals values({a:1,b:3,c:2}), [1,3,2]
patch: ->
x = {a:{foo:1,bar:3},b:2}
patch x, 'a', 'foo', 5
assertEquals x.a.foo, 5
",
input: "runtime\\glass.coffee",
content: {
require: {
String: true
},
isFunction: function(object) {
return (object != null) && typeof object === 'function';
},
isString: function(object) {
return (object != null ? object.constructor: void 0) === String;
},
isArray: function(object) {
return Array.isArray(object);
},
isBoolean: function(object) {
return (object != null) && typeof object === 'boolean';
},
isNumber: function(object) {
return (object != null) && typeof object === 'number';
},
isObject: function(object) {
return typeof object === 'object';
},
isPlainObject: function(object) {
return (object != null ? object.constructor: void 0) === Object;
},
isPrototype: function(object) {
return (object != null) && object === object.constructor.prototype;
},
isDate: function(object) {
return (object != null ? object.constructor: void 0) === Date;
},
isPrimitive: function(object) {
return isString(object) || isBoolean(object) || isNumber(object) || isDate(object);
},
isPrivate: function(property) {
return (property != null ? property[0] : void 0) === '_';
},
values: function(object) {
var key, value, _results;
_results = [];
for (key in object) {
value = object[key];
_results.push(value);
}
return _results;
},
patch: function() {
var patch, pathAndPatch, target;
target = arguments[0],
pathAndPatch = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
patch = JSONMergePatch.create.apply(null, pathAndPatch);
if (isFunction(target != null ? target.patch: void 0)) {
return target.patch(patch);
} else {
return glass.JSONMergePatch.apply(target, patch);
}
},
assert: function(a) {
if (!a) {
return _throwAssertionFailure(JSON.stringify(a));
}
},
assertTrue: function(a) {
if (a !== true) {
return _throwAssertionFailure(JSON.stringify(a) + " != true");
}
},
assertEquals: function(a, b) {
if (JSON.stringify(a) !== JSON.stringify(b)) {
return _throwAssertionFailure(JSON.stringify(a) + ' != ' + JSON.stringify(b));
}
},
getId: {
do: function() {
var counter;
counter = 0;
return function(a) {
var _ref;
if (a === null) {
return '__null__';
}
if (a === void 0) {
return '__undefined__';
}
if (typeof a === 'object' || typeof a === 'function') {
return (_ref = a.id) != null ? _ref: a.id = '__' + (counter++) + '__';
}
return a.toString();
};
}
},
getType: function(path) {
var array, step, value, _i, _len;
array = isArray(path) ? path: path.split('.');
value = global;
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
if (!isFunction(value)) {
throw new Error("Type not found: " + path);
}
return value;
},
test: {
values: function() {
return assertEquals(values({
a: 1,
b: 3,
c: 2
}), [1, 3, 2]);
},
patch: function() {
var x;
x = {
a: {
foo: 1,
bar: 3
},
b: 2
};
patch(x, 'a', 'foo', 5);
return assertEquals(x.a.foo, 5);
}
},
name: "glass",
path: "glass",
namespace: ""
}
},
String: {
source: "extension: true
properties:
\tstartsWith: (s) -> @slice(0,s.length) is s
\tendsWith: (s) -> @slice(-s.length) is s
\tcontains: (s) -> @indexOf(s) >= 0
\ttoArray: () -> @split ''",
input: "runtime\\String.coffee",
content: {
extension: true,
properties: {
startsWith: function(s) {
return this.slice(0, s.length) === s;
},
endsWith: function(s) {
return this.slice( - s.length) === s;
},
contains: function(s) {
return this.indexOf(s) >= 0;
},
toArray: function() {
return this.split('');
}
},
name: "String",
path: "String",
namespace: ""
}
}
}
} | {
options: {
input: {
dir: "runtime",
match: /\.(coffee|pegjs)$/
},
output: {
dir: "www/js"
},
script: {
includes: "www/includes.html",
prefix: "/js/"
},
module: {
main: "glass.js",
prefix: "./www/js/"
},
debug: "buildlog.html",
test: "glass.allTests",
addon: {
pregenerate: {
addUri: function(schema) {
var content, type, typeName, _ref2, _ref3;
_ref2 = schema.types;
for (typeName in _ref2) {
type = _ref2[typeName];
content = type.content;
if (content.extension) {
continue;
}
if ((_ref3 = content.uri) == null) {
content.uri = "global:/" + (content.path.replace(/\./g, '/'));
}
}
return schema;
}
}
},
namespace: ""
},
types: {
"glass.Component": {
source: "extends: 'Observable'
constructor: (properties) ->
@patch properties
# now site ourselves on our parent
if @parent
id = getId @
patch @parent, id, @
@
properties:
id:
description: 'string which uniquely identifies this component within its parent'
type: 'string'
parent:
description: 'the object that contains this component'
serializable: false
type: 'object'
disposed: false
dispose: -> @patch 'disposed', true
notify: (change) ->
Observable.prototype.notify.apply this, arguments
if change?.disposed
# dispose of any disposable children
for id, child of @ when child?.parent is @
child.dispose?()
# remove self from parent
if @id and @parent
patch @parent, @id, undefined
return
test:
lifecycle: ->
parent = new Component
assert not parent.id?
assert not parent.parent?
child = new Component parent:parent
# id should be automatically assigned
assert isString child.id
assert parent is child.parent
assert parent[child.id] is child
assert parent.hasOwnProperty child.id
parent.dispose()
assert child.disposed is true
assert not parent.hasOwnProperty child.id
nonEnumerability: ->
visibleKeys = (key for key of new Component)
assertEquals visibleKeys, []",
input: "runtime\\glass\\Component.coffee",
content: {
extends: "Observable",
constructor: function(properties) {
var id;
this.patch(properties);
if (this.parent) {
id = getId(this);
patch(this.parent, id, this);
}
return this;
},
properties: {
id: {
description: "string which uniquely identifies this component within its parent",
type: "string"
},
parent: {
description: "the object that contains this component",
serializable: false,
type: "object"
},
disposed: false,
dispose: function() {
return this.patch('disposed', true);
},
notify: function(change) {
var child, id;
Observable.prototype.notify.apply(this, arguments);
if (change != null ? change.disposed: void 0) {
for (id in this) {
child = this[id];
if ((child != null ? child.parent: void 0) === this) {
if (typeof child.dispose === "function") {
child.dispose();
}
}
}
if (this.id && this.parent) {
patch(this.parent, this.id, void 0);
}
}
}
},
test: {
lifecycle: function() {
var child, parent;
parent = new Component;
assert(!(parent.id != null));
assert(!(parent.parent != null));
child = new Component({
parent: parent
});
assert(isString(child.id));
assert(parent === child.parent);
assert(parent[child.id] === child);
assert(parent.hasOwnProperty(child.id));
parent.dispose();
assert(child.disposed === true);
return assert(!parent.hasOwnProperty(child.id));
},
nonEnumerability: function() {
var key, visibleKeys;
visibleKeys = (function() {
var _results;
_results = [];
for (key in new Component) {
_results.push(key);
}
return _results;
})();
return assertEquals(visibleKeys, []);
}
},
name: "Component",
path: "glass.Component",
namespace: "glass"
}
},
"glass.Container": {
source: "extends: 'Observable'
properties:
watch: ->
unwatch: ->
",
input: "runtime\\glass\\Container.coffee",
content: {
extends: "Observable",
properties: {
watch: function() {},
unwatch: function() {}
},
name: "Container",
path: "glass.Container",
namespace: "glass"
}
},
"glass.Expression._parser": {
source: "{
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e,array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++)
array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
}
start = expression
expression = conditional
conditional = e:or args:(\"?\" b:expression \":\" c:expression {return [b,c];})* {
while (args.length > 0) {
e = expr(\"?:\", [e].concat(args.pop()));
}
return e;
}
or = a:and b:((\"or\") and)* { return joinLeft(a,b); }
and = a:equality b:((\"and\") equality)* { return joinLeft(a,b); }
equality = a:rel b:((\"==\" / \"!=\") rel)* { return joinLeft(a,b); }
rel = a:sum b:((\"<=\" / \">=\" / \"<\" / \">\") sum)* { return joinLeft(a,b); }
sum = a:product b:((\"+\" / \"-\") product)* { return joinLeft(a,b); }
product = a:not b:((\"*\" / \"div\" / \"mod\") not)* { return joinLeft(a,b); }
not = ops:(s op:(\"!\" / \"~\" / \"+\" / \"-\") { return op; })* b:primary { return unaryRight(ops,b); }
primary = s a:(group / literal / path) s { return a; }
group = \"(\" a:expression \")\" { return a; }
literal = s a:(boolean / number / string / array / object) s { return a; }
boolean = a:(\"true\" / \"false\") { return a == \"true\"; }
number = a:([0-9]+ (\".\" [0-9]+)?) { return parseFloat(toString(a)); }
hex = [a-fA-F0-9]
// as per JSON http://www.json.org
string = a:( '\"' (
[\\u0000-\\u0021\\u0023-\\u005c\\u005e-\\uffff] // all unicode chars except \\ and \"
/ (\"\\\\\" (\"\\\"\" / \"\\\\\" / \"\\/\" / \"b\" / \"f\" / \"n\" / \"r\" / \"t\" / (\"u\" hex hex hex hex)))
)* '\"' )
{ return JSON.parse(toString(a)); }
array = \"[\" a:values \"]\" { return expr(\"array\", a); }
values = first:expression? args:(\",\" b:expression {return b;})* {
if (first != \"\") { args.unshift(first); } return args;
}
object = \"{\" a:keyvalues \"}\" { return expr(\"object\", a); }
keyvalue = s a:string s \":\" b:expression { return [a,b]; }
keyvalues = first:keyvalue? rest:(\",\" b:keyvalue {return b;})* {
if (first) { rest.unshift(first); } return rest;
}
ref = a:(\"//\" / \"/\" / \"$\" / \"**\" / \"*\" / \"..\" / \".\") b:slashProperty? {
e = expr(a); if (b) { b.args.unshift(e); e = b; } return e;
}
/ a:id { return expr(\"ref\", [a]); }
id = a:[a-z_]+ b:[a-z_0-9]* { return a.join('') + b.join(''); }
property = \"/\" a:slashProperty { return a; }
/ \"{\" a:expression \"}\" { return expr(\"{}\", [a]); } // locally scoped expression
/ \"[\" a:expression \"]\" { return expr(\"[]\", [a]); } // predicate
slashProperty = a:(id/number/string) { return expr(\"/\", [a]); }
/ a:(\"..\" / \"*\") { return expr(a, []); }
s \"space\" = [ ]* { return ''; }
path = a:root b:step* {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
}
root = a:implicitDotRoot b:dotStep? { return joinPath(a,b); }
/ explicitDotRoot
step = \".\" a:dotStep { return a; }
/ noDotStep
implicitDotRoot = \"/\" { return expr(\"root\"); }
/ \"@\" { return expr(\"this\"); }
/ \".\" a:\".\"+ { return expr(\"ancestor\", [a.length]); }
explicitDotRoot = a:id { return expr(\"ref\", [a]); }
/ \"*\" { return expr(\"values\", []); }
dotStep = a:(id / string / number) { return expr(\"get\", [a]); }
/ \"*\" { return expr(\"values\", []); }
noDotStep = \"{\" a:expression \"}\" { return expr(\"eval\", [a]); }
/ \"[\" a:expression \"]\" { return expr(\"pred\", [a]); }
/ \"(\" a:values \")\" { return expr(\"call\", [a]); }
",
input: "runtime\\glass\\Expression\\_parser.pegjs",
content: {
value: {
parse: function(input, startRule) {
var parseFunctions = {
"conditional": parse_conditional,
"or": parse_or,
"and": parse_and,
"equality": parse_equality,
"rel": parse_rel,
"sum": parse_sum,
"product": parse_product,
"not": parse_not,
"primary": parse_primary,
"group": parse_group,
"literal": parse_literal,
"boolean": parse_boolean,
"number": parse_number,
"hex": parse_hex,
"string": parse_string,
"array": parse_array,
"values": parse_values,
"object": parse_object,
"keyvalue": parse_keyvalue,
"keyvalues": parse_keyvalues,
"ref": parse_ref,
"id": parse_id,
"property": parse_property,
"slashProperty": parse_slashProperty,
"s": parse_s,
"path": parse_path,
"root": parse_root,
"step": parse_step,
"implicitDotRoot": parse_implicitDotRoot,
"explicitDotRoot": parse_explicitDotRoot,
"dotStep": parse_dotStep,
"noDotStep": parse_noDotStep
};
if (startRule !== undefined) {
if (parseFunctions[startRule] === undefined) {
throw new Error("Invalid rule name: " + quote(startRule) + ".");
}
} else {
startRule = "conditional";
}
var pos = 0;
var reportFailures = 0;
var rightmostFailuresPos = 0;
var rightmostFailuresExpected = [];
function padLeft(input, padding, length) {
var result = input;
var padLength = length - input.length;
for (var i = 0; i < padLength; i++) {
result = padding + result;
}
return result;
}
function escape(ch) {
var charCode = ch.charCodeAt(0);
var escapeChar;
var length;
if (charCode <= 0xFF) {
escapeChar = 'x';
length = 2;
} else {
escapeChar = 'u';
length = 4;
}
return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
}
function matchFailed(failure) {
if (pos < rightmostFailuresPos) {
return;
}
if (pos > rightmostFailuresPos) {
rightmostFailuresPos = pos;
rightmostFailuresExpected = [];
}
rightmostFailuresExpected.push(failure);
}
function parse_conditional() {
var result0, result1, result2, result3, result4, result5;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_or();
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, e, args) {
while (args.length > 0) {
e = expr("?:", [e].concat(args.pop()));
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_or() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_and();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_and() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_equality();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_equality() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_rel();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_rel() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_sum();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_sum() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_product();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_product() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_not();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_not() {
var result0, result1, result2;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = [];
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
while (result1 !== null) {
result0.push(result1);
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
}
if (result0 !== null) {
result1 = parse_primary();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, ops, b) {
return unaryRight(ops, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_primary() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_group();
if (result1 === null) {
result1 = parse_literal();
if (result1 === null) {
result1 = parse_path();
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_group() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_literal() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_boolean();
if (result1 === null) {
result1 = parse_number();
if (result1 === null) {
result1 = parse_string();
if (result1 === null) {
result1 = parse_array();
if (result1 === null) {
result1 = parse_object();
}
}
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_boolean() {
var result0;
var pos0;
pos0 = pos;
if (input.substr(pos, 4) === "true") {
result0 = "true";
pos += 4;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"true\"");
}
}
if (result0 === null) {
if (input.substr(pos, 5) === "false") {
result0 = "false";
pos += 5;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"false\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a == "true";
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_number() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
pos2 = pos;
if (input.charCodeAt(pos) === 46) {
result1 = ".";
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result1 !== null) {
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result3 !== null) {
result2 = [];
while (result3 !== null) {
result2.push(result3);
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result2 = null;
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos2;
}
} else {
result1 = null;
pos = pos2;
}
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return parseFloat(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_hex() {
var result0;
if (/^[a-fA-F0-9]/.test(input.charAt(pos))) {
result0 = input.charAt(pos);
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("[a-fA-F0-9]");
}
}
return result0;
}
function parse_string() {
var result0, result1, result2, result3, result4, result5, result6, result7;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 34) {
result0 = "\"";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result0 !== null) {
result1 = [];
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
}
if (result1 !== null) {
if (input.charCodeAt(pos) === 34) {
result2 = "\"";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return JSON.parse(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_array() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("array", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_values() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_conditional();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, args) {
if (first != "") {
args.unshift(first);
}
return args;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_object() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_keyvalues();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("object", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalue() {
var result0, result1, result2, result3, result4;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_string();
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
if (input.charCodeAt(pos) === 58) {
result3 = ":";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result3 !== null) {
result4 = parse_conditional();
if (result4 !== null) {
result0 = [result0, result1, result2, result3, result4];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return [a, b];
})(pos0, result0[1], result0[4]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalues() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_keyvalue();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, rest) {
if (first) {
rest.unshift(first);
}
return rest;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_ref() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.substr(pos, 2) === "//") {
result0 = "//";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"//\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 36) {
result0 = "$";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"$\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "**") {
result0 = "**";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"**\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
}
}
}
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
e = expr(a);
if (b) {
b.args.unshift(e);
e = b;
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_id() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
result1 = [];
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return a.join('') + b.join('');
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_property() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("{}", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("[]", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_slashProperty() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_number();
if (result0 === null) {
result0 = parse_string();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("/", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(a, []);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_s() {
var result0, result1;
var pos0;
reportFailures++;
pos0 = pos;
result0 = [];
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
while (result1 !== null) {
result0.push(result1);
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
}
if (result0 !== null) {
result0 = (function(offset) {
return '';
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
reportFailures--;
if (reportFailures === 0 && result0 === null) {
matchFailed("space");
}
return result0;
}
function parse_path() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_root();
if (result0 !== null) {
result1 = [];
result2 = parse_step();
while (result2 !== null) {
result1.push(result2);
result2 = parse_step();
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_root() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_implicitDotRoot();
if (result0 !== null) {
result1 = parse_dotStep();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinPath(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_explicitDotRoot();
}
return result0;
}
function parse_step() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
result1 = parse_dotStep();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_noDotStep();
}
return result0;
}
function parse_implicitDotRoot() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("root");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 64) {
result0 = "@";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"@\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("this");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result2 !== null) {
result1 = [];
while (result2 !== null) {
result1.push(result2);
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
} else {
result1 = null;
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ancestor", [a.length]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_explicitDotRoot() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_dotStep() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_string();
if (result0 === null) {
result0 = parse_number();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("get", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_noDotStep() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("eval", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("pred", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("call", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function cleanupExpected(expected) {
expected.sort();
var lastExpected = null;
var cleanExpected = [];
for (var i = 0; i < expected.length; i++) {
if (expected[i] !== lastExpected) {
cleanExpected.push(expected[i]);
lastExpected = expected[i];
}
}
return cleanExpected;
}
function computeErrorPosition() {
/*
* The first idea was to use |String.split| to break the input up to the
* error position along newlines and derive the line and column from
* there. However IE's |split| implementation is so broken that it was
* enough to prevent it.
*/
var line = 1;
var column = 1;
var seenCR = false;
for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
var ch = input.charAt(i);
if (ch === "
") {
if (!seenCR) {
line++;
}
column = 1;
seenCR = false;
} else if (ch === "
" || ch === "\u2028" || ch === "\u2029") {
line++;
column = 1;
seenCR = true;
} else {
column++;
seenCR = false;
}
}
return {
line: line,
column: column
};
}
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e, array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++) array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
var result = parseFunctions[startRule]();
/*
* The parser is now in one of the following three states:
*
* 1. The parser successfully parsed the whole input.
*
* - |result !== null|
* - |pos === input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 2. The parser successfully parsed only a part of the input.
*
* - |result !== null|
* - |pos < input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 3. The parser did not successfully parse any part of the input.
*
* - |result === null|
* - |pos === 0|
* - |rightmostFailuresExpected| contains at least one failure
*
* All code following this comment (including called functions) must
* handle these states.
*/
if (result === null || pos !== input.length) {
var offset = Math.max(pos, rightmostFailuresPos);
var found = offset < input.length ? input.charAt(offset) : null;
var errorPosition = computeErrorPosition();
throw new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column);
}
return result;
},
toSource: function() {
return this._source;
},
SyntaxError: function(expected, found, offset, line, column) {
function buildMessage(expected, found) {
var expectedHumanized, foundHumanized;
switch (expected.length) {
case 0:
expectedHumanized = "end of input";
break;
case 1:
expectedHumanized = expected[0];
break;
default:
expectedHumanized = expected.slice(0, expected.length - 1).join(", ") + " or " + expected[expected.length - 1];
}
foundHumanized = found ? quote(found) : "end of input";
return "Expected " + expectedHumanized + " but " + foundHumanized + " found.";
}
this.name = "SyntaxError";
this.expected = expected;
this.found = found;
this.message = buildMessage(expected, found);
this.offset = offset;
this.line = line;
this.column = column;
}
},
name: "_parser",
path: "glass.Expression._parser",
namespace: "glass.Expression"
}
},
"glass.Expression": {
source: "constructor: (op, args) ->
@op = op
@args = args if args?
@
properties:
op:
type: 'string'
args:
type: 'array'
test: ->
return
peg = require 'pegjs'
fs = require 'fs'
parserSource = fs.readFileSync 'runtime/glass/Expression/_parser.pegjs', 'utf8'
parser = peg.buildParser parserSource
tests =
\"a.b.c\": {op:\"get\",args:[{op:\"get\",args:[{op:\"ref\",args:[\"a\"]},\"b\"]},\"c\"]}
\"a.1\": {op:\"get\",args:[{op:\"ref\",args:[\"a\"]},1]}
\"true\": true
\"false\": false
\"45.8\": 45.8
\"(45.8)\": 45.8
\"((45.8))\": 45.8
\"alpha\": {op:\"ref\",args:[\"alpha\"]}
\"35 + true * 2\": {op:\"+\", args:[35, {op:\"*\", args:[true,2]}]}
\" 5 * ( 2 + 2 ) \": {op:\"*\", args:[5, {op:\"+\", args:[2,2]}]}
\" ! ! true\": {op:\"!\",args:[{op:\"!\",args:[true]}]}
\"5 + -x\": {op:\"+\",args:[5,{op:\"-\",args:[{op:\"ref\",args:[\"x\"]}]}]}
\"true == 5 >= 2\": {op:\"==\",args:[true,{op:\">=\",args:[5,2]}]}
\"1 or 2 and 3\": {op:\"or\",args:[1,{op:\"and\",args:[2,3]}]}
\"1 ? 2 : 3\": {op:\"?:\",args:[1,2,3]}
\"1 ? 2 : 3 ? 4 : 5\" : {op:\"?:\",args:[1,2,{op:\"?:\",args:[3,4,5]}]}
\"a()(1,2)\" : {op:\"call\",args:[{op:\"call\",args:[{op:\"ref\",args:[\"a\"]},[]]},[1,2]]}
\"@\" : {op:\"this\"}
\"@foo\" : {op:\"get\",args:[{op:\"this\"},\"foo\"]}
'\"hello\"': \"hello\"
'\"\\\\t\\
\\
\\\\b\\\\\\\\foo\\\\\\/\"' : \"\\t
\\b\\\\foo\\/\"
\"[]\": {op:\"array\",args:[]}
\"[1,2]\": {op:\"array\",args:[1,2]}
\"[1+2]\": {op:\"array\",args:[{op:\"+\",args:[1,2]}]}
\"{}\": {op:\"object\",args:[]}
'{\"a\":2}': {op:\"object\",args:[[\"a\",2]]}
'{\"a\":2,\"b\":1+2}': {op:\"object\",args:[[\"a\",2],[\"b\",{op:\"+\",args:[1,2]}]]}
'@\"alpha\"': {op:\"get\",args:[{op:\"this\"},\"alpha\"]}
'*': {op:\"values\",args:[]}
'*.*': {op:\"values\",args:[{op:\"values\",args:[]}]}
\"foo.*\": {op:\"values\",args:[{op:\"ref\",args:[\"foo\"]}]}
\"..\": {op:\"ancestor\",args:[1]}
\"...\": {op:\"ancestor\",args:[2]}
\"@*{1+2}\": {op:\"eval\",args:[{op:\"values\",args:[{op:\"this\"}]},{op:\"+\",args:[1,2]}]}
\"/\": {op:\"root\"}
\"/foo\": {op:\"get\",args:[{op:\"root\"},\"foo\"]}
\"/*\": {op:\"values\",args:[{op:\"root\"}]}
for text, expected of tests
result = parser.parse text
if JSON.stringify(result) is JSON.stringify(expected)
console.log 'Pass: ' + text
else
console.log text, JSON.stringify result
return
",
input: "runtime\\glass\\Expression.coffee",
content: {
constructor: function(op, args) {
this.op = op;
if (args != null) {
this.args = args;
}
return this;
},
properties: {
op: {
type: "string"
},
args: {
type: "array"
}
},
test: function() {
var expected, fs, parser, parserSource, peg, result, tests, text;
return;
peg = require('pegjs');
fs = require('fs');
parserSource = fs.readFileSync('runtime/glass/Expression/_parser.pegjs', 'utf8');
parser = peg.buildParser(parserSource);
tests = {
"a.b.c": {
op: "get",
args: [{
op: "get",
args: [{
op: "ref",
args: ["a"]
},
"b"]
},
"c"]
},
"a.1": {
op: "get",
args: [{
op: "ref",
args: ["a"]
},
1]
},
"true": true,
"false": false,
"45.8": 45.8,
"(45.8)": 45.8,
"((45.8))": 45.8,
"alpha": {
op: "ref",
args: ["alpha"]
},
"35 + true * 2": {
op: "+",
args: [35, {
op: "*",
args: [true, 2]
}]
},
" 5 * ( 2 + 2 ) ": {
op: "*",
args: [5, {
op: "+",
args: [2, 2]
}]
},
" ! ! true": {
op: "!",
args: [{
op: "!",
args: [true]
}]
},
"5 + -x": {
op: "+",
args: [5, {
op: "-",
args: [{
op: "ref",
args: ["x"]
}]
}]
},
"true == 5 >= 2": {
op: "==",
args: [true, {
op: ">=",
args: [5, 2]
}]
},
"1 or 2 and 3": {
op: "or",
args: [1, {
op: "and",
args: [2, 3]
}]
},
"1 ? 2 : 3": {
op: "?:",
args: [1, 2, 3]
},
"1 ? 2 : 3 ? 4 : 5": {
op: "?:",
args: [1, 2, {
op: "?:",
args: [3, 4, 5]
}]
},
"a()(1,2)": {
op: "call",
args: [{
op: "call",
args: [{
op: "ref",
args: ["a"]
},
[]]
},
[1, 2]]
},
"@": {
op: "this"
},
"@foo": {
op: "get",
args: [{
op: "this"
},
"foo"]
},
'"hello"': "hello",
'"\\t
\\b\\\\foo\\\/"': "\t
\b\\foo\/",
"[]": {
op: "array",
args: []
},
"[1,2]": {
op: "array",
args: [1, 2]
},
"[1+2]": {
op: "array",
args: [{
op: "+",
args: [1, 2]
}]
},
"{}": {
op: "object",
args: []
},
'{"a":2}': {
op: "object",
args: [["a", 2]]
},
'{"a":2,"b":1+2}': {
op: "object",
args: [["a", 2], ["b", {
op: "+",
args: [1, 2]
}]]
},
'@"alpha"': {
op: "get",
args: [{
op: "this"
},
"alpha"]
},
'*': {
op: "values",
args: []
},
'*.*': {
op: "values",
args: [{
op: "values",
args: []
}]
},
"foo.*": {
op: "values",
args: [{
op: "ref",
args: ["foo"]
}]
},
"..": {
op: "ancestor",
args: [1]
},
"...": {
op: "ancestor",
args: [2]
},
"@*{1+2}": {
op: "eval",
args: [{
op: "values",
args: [{
op: "this"
}]
},
{
op: "+",
args: [1, 2]
}]
},
"/": {
op: "root"
},
"/foo": {
op: "get",
args: [{
op: "root"
},
"foo"]
},
"/*": {
op: "values",
args: [{
op: "root"
}]
}
};
for (text in tests) {
expected = tests[text];
result = parser.parse(text);
if (JSON.stringify(result) === JSON.stringify(expected)) {
console.log('Pass: ' + text);
} else {
console.log(text, JSON.stringify(result));
}
}
},
name: "Expression",
path: "glass.Expression",
namespace: "glass"
}
},
"glass.JSONMergePatch": {
source: "
# applies a patch to the target object and returns the resulting target
apply: (target, patch) ->
if target? and target isnt patch and isPlainObject(patch) and not isPrimitive(target)
for key, value of patch
if value is undefined
delete target[key]
else
target[key] = apply target[key], patch[key]
return target
else
return patch
# (path1, path2, path3.., patch) ->
create: ->
if arguments.length is 1
return arguments[0]
result = {}
current = result
for arg, i in arguments when i + 1 < arguments.length
last = i + 2 is arguments.length
current = current[arg] = if last then arguments[arguments.length-1] else {}
result
test: ->
assertEquals {a:{b:12}}, create 'a', 'b', 12
assertEquals {a:3}, apply({a:1,b:2}, {a:3,b:undefined})
",
input: "runtime\\glass\\JSONMergePatch.coffee",
content: {
apply: function(target, patch) {
var key, value;
if ((target != null) && target !== patch && isPlainObject(patch) && !isPrimitive(target)) {
for (key in patch) {
value = patch[key];
if (value === void 0) {
delete target[key];
} else {
target[key] = apply(target[key], patch[key]);
}
}
return target;
} else {
return patch;
}
},
create: function() {
var arg, current, i, last, result, _i, _len;
if (arguments.length === 1) {
return arguments[0];
}
result = {};
current = result;
for (i = _i = 0, _len = arguments.length; _i < _len; i = ++_i) {
arg = arguments[i];
if (! (i + 1 < arguments.length)) {
continue;
}
last = i + 2 === arguments.length;
current = current[arg] = last ? arguments[arguments.length - 1] : {};
}
return result;
},
test: function() {
assertEquals({
a: {
b: 12
}
},
create('a', 'b', 12));
return assertEquals({
a: 3
},
apply({
a: 1,
b: 2
},
{
a: 3,
b: void 0
}));
},
name: "JSONMergePatch",
path: "glass.JSONMergePatch",
namespace: "glass"
}
},
"glass.JSONPointer": {
source: "# json pointer implementation as per
# http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-05
_decodeStep: (step) -> step.replace(/~1/g, '/').replace(/~0/g, '~')
_getLastStep: (pointer) ->
_decodeStep pointer.substring(pointer.lastIndexOf('/') + 1)
_getParent: (pointer) ->
if not pointer?.length
null
else
pointer.substring(0, pointer.lastIndexOf('/'))
toArray: (pointer) ->
for step in pointer.substring(1).split('/')
_decodeStep step
get: (doc, pointer) ->
value = doc
if pointer.length
path = toArray pointer
for step in path when value?
value = value[step]
value
set: (doc, pointer, value) ->
parentPointer = _getParent pointer
if parentPointer?
parent = get doc, parentPointer
lastStep = _getLastStep pointer
parent[lastStep] = value
value
test: ->
assertEquals _getParent(\"/a/b/c\"), \"/a/b\"
assertEquals _getParent(\"/a\"), \"\"
assertEquals _getParent(\"\"), null
assertEquals _getLastStep(\"/a/b/c\"), \"c\"
assertEquals _getLastStep(\"/a~0~1\"), \"a~/\"
assertEquals _getLastStep(\"\"), \"\"
# tests as per spec
doc = {
\"foo\": [\"bar\", \"baz\"],
\"\": 0,
\"a/b\": 1,
\"c%d\": 2,
\"e^f\": 3,
\"g|h\": 4,
\"i\\\\j\": 5,
\"k\\\"l\": 6,
\" \": 7,
\"m~n\": 8
}
assertEquals get(doc, \"\"), doc
assertEquals get(doc, \"/foo\"), [\"bar\", \"baz\"]
assertEquals get(doc, \"/foo/0\"), \"bar\"
assertEquals get(doc, \"/\"), 0
assertEquals get(doc, \"/a~1b\"), 1
assertEquals get(doc, \"/c%d\"), 2
assertEquals get(doc, \"/e^f\"), 3
assertEquals get(doc, \"/g|h\"), 4
assertEquals get(doc, \"/i\\\\j\"), 5
assertEquals get(doc, \"/k\\\"l\"), 6
assertEquals get(doc, \"/ \"), 7
assertEquals get(doc, \"/m~0n\"), 8
# now test set
assertEquals set(doc, \"/\", 10), 10
assertEquals doc[\"\"], 10
assertEquals set(doc, \"/foo/0\", 10), 10
assertEquals doc.foo[0], 10",
input: "runtime\\glass\\JSONPointer.coffee",
content: {
toArray: function(pointer) {
var step, _i, _len, _ref, _results;
_ref = pointer.substring(1).split('/');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
step = _ref[_i];
_results.push(_decodeStep(step));
}
return _results;
},
get: function(doc, pointer) {
var path, step, value, _i, _len;
value = doc;
if (pointer.length) {
path = toArray(pointer);
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
}
return value;
},
set: function(doc, pointer, value) {
var lastStep, parent, parentPointer;
parentPointer = _getParent(pointer);
if (parentPointer != null) {
parent = get(doc, parentPointer);
lastStep = _getLastStep(pointer);
parent[lastStep] = value;
}
return value;
},
test: function() {
var doc;
assertEquals(_getParent("/a/b/c"), "/a/b");
assertEquals(_getParent("/a"), "");
assertEquals(_getParent(""), null);
assertEquals(_getLastStep("/a/b/c"), "c");
assertEquals(_getLastStep("/a~0~1"), "a~/");
assertEquals(_getLastStep(""), "");
doc = {
"foo": ["bar", "baz"],
"": 0,
"a/b": 1,
"c%d": 2,
"e^f": 3,
"g|h": 4,
"i\\j": 5,
"k\"l": 6,
" ": 7,
"m~n": 8
};
assertEquals(get(doc, ""), doc);
assertEquals(get(doc, "/foo"), ["bar", "baz"]);
assertEquals(get(doc, "/foo/0"), "bar");
assertEquals(get(doc, "/"), 0);
assertEquals(get(doc, "/a~1b"), 1);
assertEquals(get(doc, "/c%d"), 2);
assertEquals(get(doc, "/e^f"), 3);
assertEquals(get(doc, "/g|h"), 4);
assertEquals(get(doc, "/i\\j"), 5);
assertEquals(get(doc, "/k\"l"), 6);
assertEquals(get(doc, "/ "), 7);
assertEquals(get(doc, "/m~0n"), 8);
assertEquals(set(doc, "/", 10), 10);
assertEquals(doc[""], 10);
assertEquals(set(doc, "/foo/0", 10), 10);
return assertEquals(doc.foo[0], 10);
},
name: "JSONPointer",
path: "glass.JSONPointer",
namespace: "glass"
}
},
"glass.Observable": {
source: "properties:
is: (type) -> @constructor.implements[type.path ? type] is true
watchers:
serializable: false
watch: (property, watcher) ->
if isFunction property
watcher = property
property = ''
id = getId watcher
@patch 'watchers', property, id, watcher
# returns a function which will remove the watch
=> @patch 'watchers', property, getId(watcher), undefined
patch: (change) ->
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
try
JSONMergePatch.apply this, change
catch e
console.log e
finally
@notify change
return
notify: (change) ->
if @watchers?
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
for property, watchers of @watchers
if property.length is 0 or change.hasOwnProperty property
changeArg = if property.length is 0 then change else change[property]
for id, watcher of watchers
watcher this, changeArg
return
toJSON: ->
values =
class: @constructor.path
# serialize statically defined properties
for name, property of @constructor.properties
value = @[name]
if property.serializable isnt false and not isFunction(value)
values[name] = value
# serialize custom properties if allowed by schema
if @constructor.additionalProperties isnt false
for own name, value of @ when not isPrivate name
values[name] = value
values
toString: -> @toJSON()
test:
toJSON: ->
# I need this test later
# on a class that actually has serializable properties
a = new Observable
a.x = 12
a.y = ->
a.z = true
assertEquals a, {class:'glass.Observable', x:12,z:true}
watchAll: ->
# we should actually be able to watch ourselves get added to watchers
# this is very meta.
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch watcher
# now make sure we were called with our own watcher
assert watchArgs[0] is a
assert watchArgs[1]?.watchers?[\"\"]?
# reset watchArgs, and watch something else
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assertEquals a.a, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {a:{b:3}}
# now unwatch
unwatch()
# make sure universal watcher is now empty
assertEquals a.watchers[\"\"], {}
# now reset and do a new event, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
watchProperty: ->
# watch a property
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch \"foo\", watcher
# now make sure we were not called
assert watchArgs.length is 0
# reset watchArgs, and watch something else
a.patch \"foo\", \"b\", 3
assertEquals a.foo, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {b:3}
# now reset and do a different property, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
# now unwatch
unwatch()
# make sure we no longer see foo
watchArgs.length = 0
a.patch \"foo\", \"b\", 4
assert watchArgs.length is 0
",
input: "runtime\\glass\\Observable.coffee",
content: {
properties: {
is: function(type) {
var _ref;
return this.constructor["implements"][(_ref = type.path) != null ? _ref: type] === true;
},
watchers: {
serializable: false
},
watch: function(property, watcher) {
var id, _this = this;
if (isFunction(property)) {
watcher = property;
property = '';
}
id = getId(watcher);
this.patch('watchers', property, id, watcher);
return function() {
return _this.patch('watchers', property, getId(watcher), void 0);
};
},
patch: function(change) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
try {
JSONMergePatch.apply(this, change);
} catch(e) {
console.log(e);
} finally {
this.notify(change);
}
},
notify: function(change) {
var changeArg, id, property, watcher, watchers, _ref;
if (this.watchers != null) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
_ref = this.watchers;
for (property in _ref) {
watchers = _ref[property];
if (property.length === 0 || change.hasOwnProperty(property)) {
changeArg = property.length === 0 ? change: change[property];
for (id in watchers) {
watcher = watchers[id];
watcher(this, changeArg);
}
}
}
}
},
toJSON: function() {
var name, property, value, values, _ref;
values = {
"class": this.constructor.path
};
_ref = this.constructor.properties;
for (name in _ref) {
property = _ref[name];
value = this[name];
if (property.serializable !== false && !isFunction(value)) {
values[name] = value;
}
}
if (this.constructor.additionalProperties !== false) {
for (name in this) {
if (!__hasProp.call(this, name)) continue;
value = this[name];
if (!isPrivate(name)) {
values[name] = value;
}
}
}
return values;
},
toString: function() {
return this.toJSON();
}
},
test: {
toJSON: function() {
var a;
a = new Observable;
a.x = 12;
a.y = function() {};
a.z = true;
return assertEquals(a, {
"class": 'glass.Observable',
x: 12,
z: true
});
},
watchAll: function() {
var a, unwatch, watchArgs, watcher, _ref, _ref1;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch(watcher);
assert(watchArgs[0] === a);
assert(((_ref = watchArgs[1]) != null ? (_ref1 = _ref.watchers) != null ? _ref1[""] : void 0 : void 0) != null);
watchArgs.length = 0;
a.patch("a", "b", 3);
assertEquals(a.a, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
a: {
b: 3
}
});
unwatch();
assertEquals(a.watchers[""], {});
watchArgs.length = 0;
a.patch("a", "b", 3);
return assert(watchArgs.length === 0);
},
watchProperty: function() {
var a, unwatch, watchArgs, watcher;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch("foo", watcher);
assert(watchArgs.length === 0);
a.patch("foo", "b", 3);
assertEquals(a.foo, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
b: 3
});
watchArgs.length = 0;
a.patch("a", "b", 3);
assert(watchArgs.length === 0);
unwatch();
watchArgs.length = 0;
a.patch("foo", "b", 4);
return assert(watchArgs.length === 0);
}
},
name: "Observable",
path: "glass.Observable",
namespace: "glass"
}
},
glass: {
source: "require:
\tString: true
# runtime type tests
isFunction: (object) -> object? and typeof object is 'function'
isString: (object) -> object?.constructor is String
isArray: (object) -> Array.isArray object
isBoolean: (object) -> object? and typeof object is 'boolean'
isNumber: (object) -> object? and typeof object is 'number'
isObject: (object) -> typeof object is 'object'
isPlainObject: (object) -> object?.constructor is Object
isPrototype: (object) -> object? and object is object.constructor.prototype
isDate: (object) -> object?.constructor is Date
isPrimitive: (object) -> isString(object) or isBoolean(object) or isNumber(object) or isDate(object)
isPrivate: (property) -> property?[0] is '_'
# generic utility functions
values: (object) -> (value for key, value of object)
# generic patch method, uses patch method built into object if present
patch: (target, pathAndPatch...) ->
patch = JSONMergePatch.create.apply null, pathAndPatch
if isFunction target?.patch
target.patch patch
else
glass.JSONMergePatch.apply target, patch
# testing assertions
_getStackLocationInfo: (e, depth) ->
line = e.stack?.split('
')[depth]
return null unless line?
match = /\\(([\\w\\W]*?):(\\d+):(\\d+)\\)/.exec line
return {
file: match[1]
line: parseInt match[2]
column: parseInt match[3]
}
_throwAssertionFailure: (message) ->
try
throw new Error \"Assertion failed: \" + message
catch e
info = _getStackLocationInfo e, 3
if info?
_dumpFile info.file, info.line - 2, info.line + 2, info.line
throw e
_dumpFile: (file, from=1, to, highlight) ->
fs = require 'fs'
return unless fs?
try
content = fs.readFileSync(file).toString()
catch e
content = \"Source not found: #{e}\"
console.log '------------------------------------------------'
console.log file
console.log '------------------------------------------------'
number = 1
if content?
lines = content.split /
|
/
to ?= lines.length
for line in lines
lineNumber = number++
if lineNumber >= from and lineNumber <= to
num = String lineNumber
while num.length < 3
num += ' '
if lineNumber is highlight
`console.log(\"\\033[91m\" + num + \": \" + line + \"\\033[0m\");`
else
`console.log(num + \": \" + line);`
console.log '------------------------------------------------'
assert: (a) ->
_throwAssertionFailure JSON.stringify(a) unless a
assertTrue: (a) ->
_throwAssertionFailure JSON.stringify(a) + \" != true\" unless a is true
assertEquals: (a, b) ->
if JSON.stringify(a) isnt JSON.stringify(b)
_throwAssertionFailure JSON.stringify(a) + ' != ' + JSON.stringify(b)
# gets a unique string identifier for any object
getId:
do: ->
counter = 0
(a) ->
if a is null
return '__null__'
if a is undefined
return '__undefined__'
if typeof a is 'object' or typeof a is 'function'
return a.id ?= '__' + (counter++) + '__'
# 12 == \"12\" under this technique
return a.toString()
getType: (path) ->
array = if isArray path then path else path.split '.'
value = global
for step in path when value?
value = value[step]
throw new Error \"Type not found: #{path}\" unless isFunction value
value
test:
values: ->
assertEquals values({a:1,b:3,c:2}), [1,3,2]
patch: ->
x = {a:{foo:1,bar:3},b:2}
patch x, 'a', 'foo', 5
assertEquals x.a.foo, 5
",
input: "runtime\\glass.coffee",
content: {
require: {
String: true
},
isFunction: function(object) {
return (object != null) && typeof object === 'function';
},
isString: function(object) {
return (object != null ? object.constructor: void 0) === String;
},
isArray: function(object) {
return Array.isArray(object);
},
isBoolean: function(object) {
return (object != null) && typeof object === 'boolean';
},
isNumber: function(object) {
return (object != null) && typeof object === 'number';
},
isObject: function(object) {
return typeof object === 'object';
},
isPlainObject: function(object) {
return (object != null ? object.constructor: void 0) === Object;
},
isPrototype: function(object) {
return (object != null) && object === object.constructor.prototype;
},
isDate: function(object) {
return (object != null ? object.constructor: void 0) === Date;
},
isPrimitive: function(object) {
return isString(object) || isBoolean(object) || isNumber(object) || isDate(object);
},
isPrivate: function(property) {
return (property != null ? property[0] : void 0) === '_';
},
values: function(object) {
var key, value, _results;
_results = [];
for (key in object) {
value = object[key];
_results.push(value);
}
return _results;
},
patch: function() {
var patch, pathAndPatch, target;
target = arguments[0],
pathAndPatch = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
patch = JSONMergePatch.create.apply(null, pathAndPatch);
if (isFunction(target != null ? target.patch: void 0)) {
return target.patch(patch);
} else {
return glass.JSONMergePatch.apply(target, patch);
}
},
assert: function(a) {
if (!a) {
return _throwAssertionFailure(JSON.stringify(a));
}
},
assertTrue: function(a) {
if (a !== true) {
return _throwAssertionFailure(JSON.stringify(a) + " != true");
}
},
assertEquals: function(a, b) {
if (JSON.stringify(a) !== JSON.stringify(b)) {
return _throwAssertionFailure(JSON.stringify(a) + ' != ' + JSON.stringify(b));
}
},
getId: {
do: function() {
var counter;
counter = 0;
return function(a) {
var _ref;
if (a === null) {
return '__null__';
}
if (a === void 0) {
return '__undefined__';
}
if (typeof a === 'object' || typeof a === 'function') {
return (_ref = a.id) != null ? _ref: a.id = '__' + (counter++) + '__';
}
return a.toString();
};
}
},
getType: function(path) {
var array, step, value, _i, _len;
array = isArray(path) ? path: path.split('.');
value = global;
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
if (!isFunction(value)) {
throw new Error("Type not found: " + path);
}
return value;
},
test: {
values: function() {
return assertEquals(values({
a: 1,
b: 3,
c: 2
}), [1, 3, 2]);
},
patch: function() {
var x;
x = {
a: {
foo: 1,
bar: 3
},
b: 2
};
patch(x, 'a', 'foo', 5);
return assertEquals(x.a.foo, 5);
}
},
name: "glass",
path: "glass",
namespace: ""
}
},
String: {
source: "extension: true
properties:
\tstartsWith: (s) -> @slice(0,s.length) is s
\tendsWith: (s) -> @slice(-s.length) is s
\tcontains: (s) -> @indexOf(s) >= 0
\ttoArray: () -> @split ''",
input: "runtime\\String.coffee",
content: {
extension: true,
properties: {
startsWith: function(s) {
return this.slice(0, s.length) === s;
},
endsWith: function(s) {
return this.slice( - s.length) === s;
},
contains: function(s) {
return this.indexOf(s) >= 0;
},
toArray: function() {
return this.split('');
}
},
name: "String",
path: "String",
namespace: ""
}
}
}
} | {
options: {
input: {
dir: "runtime",
match: /\.(coffee|pegjs)$/
},
output: {
dir: "www/js"
},
script: {
includes: "www/includes.html",
prefix: "/js/"
},
module: {
main: "glass.js",
prefix: "./www/js/"
},
debug: "buildlog.html",
test: "glass.allTests",
addon: {
pregenerate: {
addUri: function(schema) {
var content, type, typeName, _ref2, _ref3;
_ref2 = schema.types;
for (typeName in _ref2) {
type = _ref2[typeName];
content = type.content;
if (content.extension) {
continue;
}
if ((_ref3 = content.uri) == null) {
content.uri = "global:/" + (content.path.replace(/\./g, '/'));
}
}
return schema;
}
}
},
namespace: ""
},
types: {
"glass.Component": {
source: "extends: 'Observable'
constructor: (properties) ->
@patch properties
# now site ourselves on our parent
if @parent
id = getId @
patch @parent, id, @
@
properties:
id:
description: 'string which uniquely identifies this component within its parent'
type: 'string'
parent:
description: 'the object that contains this component'
serializable: false
type: 'object'
disposed: false
dispose: -> @patch 'disposed', true
notify: (change) ->
Observable.prototype.notify.apply this, arguments
if change?.disposed
# dispose of any disposable children
for id, child of @ when child?.parent is @
child.dispose?()
# remove self from parent
if @id and @parent
patch @parent, @id, undefined
return
test:
lifecycle: ->
parent = new Component
assert not parent.id?
assert not parent.parent?
child = new Component parent:parent
# id should be automatically assigned
assert isString child.id
assert parent is child.parent
assert parent[child.id] is child
assert parent.hasOwnProperty child.id
parent.dispose()
assert child.disposed is true
assert not parent.hasOwnProperty child.id
nonEnumerability: ->
visibleKeys = (key for key of new Component)
assertEquals visibleKeys, []",
input: "runtime\\glass\\Component.coffee",
content: {
extends: "Observable",
constructor: function(properties) {
var id;
this.patch(properties);
if (this.parent) {
id = getId(this);
patch(this.parent, id, this);
}
return this;
},
properties: {
id: {
description: "string which uniquely identifies this component within its parent",
type: "string",
name: "id",
writable: true
},
parent: {
description: "the object that contains this component",
serializable: false,
type: "object",
name: "parent",
writable: true
},
disposed: {
value: false,
name: "disposed",
writable: true
},
dispose: {
value: function() {
return this.patch('disposed', true);
},
name: "dispose"
},
notify: {
value: function(change) {
var child, id;
Observable.prototype.notify.apply(this, arguments);
if (change != null ? change.disposed: void 0) {
for (id in this) {
child = this[id];
if ((child != null ? child.parent: void 0) === this) {
if (typeof child.dispose === "function") {
child.dispose();
}
}
}
if (this.id && this.parent) {
patch(this.parent, this.id, void 0);
}
}
},
name: "notify"
}
},
test: {
lifecycle: function() {
var child, parent;
parent = new Component;
assert(!(parent.id != null));
assert(!(parent.parent != null));
child = new Component({
parent: parent
});
assert(isString(child.id));
assert(parent === child.parent);
assert(parent[child.id] === child);
assert(parent.hasOwnProperty(child.id));
parent.dispose();
assert(child.disposed === true);
return assert(!parent.hasOwnProperty(child.id));
},
nonEnumerability: function() {
var key, visibleKeys;
visibleKeys = (function() {
var _results;
_results = [];
for (key in new Component) {
_results.push(key);
}
return _results;
})();
return assertEquals(visibleKeys, []);
}
},
name: "Component",
path: "glass.Component",
namespace: "glass"
}
},
"glass.Container": {
source: "extends: 'Observable'
properties:
watch: ->
unwatch: ->
",
input: "runtime\\glass\\Container.coffee",
content: {
extends: "Observable",
properties: {
watch: {
value: function() {},
name: "watch"
},
unwatch: {
value: function() {},
name: "unwatch"
}
},
name: "Container",
path: "glass.Container",
namespace: "glass"
}
},
"glass.Expression._parser": {
source: "{
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e,array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++)
array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
}
start = expression
expression = conditional
conditional = e:or args:(\"?\" b:expression \":\" c:expression {return [b,c];})* {
while (args.length > 0) {
e = expr(\"?:\", [e].concat(args.pop()));
}
return e;
}
or = a:and b:((\"or\") and)* { return joinLeft(a,b); }
and = a:equality b:((\"and\") equality)* { return joinLeft(a,b); }
equality = a:rel b:((\"==\" / \"!=\") rel)* { return joinLeft(a,b); }
rel = a:sum b:((\"<=\" / \">=\" / \"<\" / \">\") sum)* { return joinLeft(a,b); }
sum = a:product b:((\"+\" / \"-\") product)* { return joinLeft(a,b); }
product = a:not b:((\"*\" / \"div\" / \"mod\") not)* { return joinLeft(a,b); }
not = ops:(s op:(\"!\" / \"~\" / \"+\" / \"-\") { return op; })* b:primary { return unaryRight(ops,b); }
primary = s a:(group / literal / path) s { return a; }
group = \"(\" a:expression \")\" { return a; }
literal = s a:(boolean / number / string / array / object) s { return a; }
boolean = a:(\"true\" / \"false\") { return a == \"true\"; }
number = a:([0-9]+ (\".\" [0-9]+)?) { return parseFloat(toString(a)); }
hex = [a-fA-F0-9]
// as per JSON http://www.json.org
string = a:( '\"' (
[\\u0000-\\u0021\\u0023-\\u005c\\u005e-\\uffff] // all unicode chars except \\ and \"
/ (\"\\\\\" (\"\\\"\" / \"\\\\\" / \"\\/\" / \"b\" / \"f\" / \"n\" / \"r\" / \"t\" / (\"u\" hex hex hex hex)))
)* '\"' )
{ return JSON.parse(toString(a)); }
array = \"[\" a:values \"]\" { return expr(\"array\", a); }
values = first:expression? args:(\",\" b:expression {return b;})* {
if (first != \"\") { args.unshift(first); } return args;
}
object = \"{\" a:keyvalues \"}\" { return expr(\"object\", a); }
keyvalue = s a:string s \":\" b:expression { return [a,b]; }
keyvalues = first:keyvalue? rest:(\",\" b:keyvalue {return b;})* {
if (first) { rest.unshift(first); } return rest;
}
ref = a:(\"//\" / \"/\" / \"$\" / \"**\" / \"*\" / \"..\" / \".\") b:slashProperty? {
e = expr(a); if (b) { b.args.unshift(e); e = b; } return e;
}
/ a:id { return expr(\"ref\", [a]); }
id = a:[a-z_]+ b:[a-z_0-9]* { return a.join('') + b.join(''); }
property = \"/\" a:slashProperty { return a; }
/ \"{\" a:expression \"}\" { return expr(\"{}\", [a]); } // locally scoped expression
/ \"[\" a:expression \"]\" { return expr(\"[]\", [a]); } // predicate
slashProperty = a:(id/number/string) { return expr(\"/\", [a]); }
/ a:(\"..\" / \"*\") { return expr(a, []); }
s \"space\" = [ ]* { return ''; }
path = a:root b:step* {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
}
root = a:implicitDotRoot b:dotStep? { return joinPath(a,b); }
/ explicitDotRoot
step = \".\" a:dotStep { return a; }
/ noDotStep
implicitDotRoot = \"/\" { return expr(\"root\"); }
/ \"@\" { return expr(\"this\"); }
/ \".\" a:\".\"+ { return expr(\"ancestor\", [a.length]); }
explicitDotRoot = a:id { return expr(\"ref\", [a]); }
/ \"*\" { return expr(\"values\", []); }
dotStep = a:(id / string / number) { return expr(\"get\", [a]); }
/ \"*\" { return expr(\"values\", []); }
noDotStep = \"{\" a:expression \"}\" { return expr(\"eval\", [a]); }
/ \"[\" a:expression \"]\" { return expr(\"pred\", [a]); }
/ \"(\" a:values \")\" { return expr(\"call\", [a]); }
",
input: "runtime\\glass\\Expression\\_parser.pegjs",
content: {
value: {
parse: function(input, startRule) {
var parseFunctions = {
"conditional": parse_conditional,
"or": parse_or,
"and": parse_and,
"equality": parse_equality,
"rel": parse_rel,
"sum": parse_sum,
"product": parse_product,
"not": parse_not,
"primary": parse_primary,
"group": parse_group,
"literal": parse_literal,
"boolean": parse_boolean,
"number": parse_number,
"hex": parse_hex,
"string": parse_string,
"array": parse_array,
"values": parse_values,
"object": parse_object,
"keyvalue": parse_keyvalue,
"keyvalues": parse_keyvalues,
"ref": parse_ref,
"id": parse_id,
"property": parse_property,
"slashProperty": parse_slashProperty,
"s": parse_s,
"path": parse_path,
"root": parse_root,
"step": parse_step,
"implicitDotRoot": parse_implicitDotRoot,
"explicitDotRoot": parse_explicitDotRoot,
"dotStep": parse_dotStep,
"noDotStep": parse_noDotStep
};
if (startRule !== undefined) {
if (parseFunctions[startRule] === undefined) {
throw new Error("Invalid rule name: " + quote(startRule) + ".");
}
} else {
startRule = "conditional";
}
var pos = 0;
var reportFailures = 0;
var rightmostFailuresPos = 0;
var rightmostFailuresExpected = [];
function padLeft(input, padding, length) {
var result = input;
var padLength = length - input.length;
for (var i = 0; i < padLength; i++) {
result = padding + result;
}
return result;
}
function escape(ch) {
var charCode = ch.charCodeAt(0);
var escapeChar;
var length;
if (charCode <= 0xFF) {
escapeChar = 'x';
length = 2;
} else {
escapeChar = 'u';
length = 4;
}
return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
}
function matchFailed(failure) {
if (pos < rightmostFailuresPos) {
return;
}
if (pos > rightmostFailuresPos) {
rightmostFailuresPos = pos;
rightmostFailuresExpected = [];
}
rightmostFailuresExpected.push(failure);
}
function parse_conditional() {
var result0, result1, result2, result3, result4, result5;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_or();
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, e, args) {
while (args.length > 0) {
e = expr("?:", [e].concat(args.pop()));
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_or() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_and();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_and() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_equality();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_equality() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_rel();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_rel() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_sum();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_sum() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_product();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_product() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_not();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_not() {
var result0, result1, result2;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = [];
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
while (result1 !== null) {
result0.push(result1);
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
}
if (result0 !== null) {
result1 = parse_primary();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, ops, b) {
return unaryRight(ops, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_primary() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_group();
if (result1 === null) {
result1 = parse_literal();
if (result1 === null) {
result1 = parse_path();
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_group() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_literal() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_boolean();
if (result1 === null) {
result1 = parse_number();
if (result1 === null) {
result1 = parse_string();
if (result1 === null) {
result1 = parse_array();
if (result1 === null) {
result1 = parse_object();
}
}
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_boolean() {
var result0;
var pos0;
pos0 = pos;
if (input.substr(pos, 4) === "true") {
result0 = "true";
pos += 4;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"true\"");
}
}
if (result0 === null) {
if (input.substr(pos, 5) === "false") {
result0 = "false";
pos += 5;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"false\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a == "true";
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_number() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
pos2 = pos;
if (input.charCodeAt(pos) === 46) {
result1 = ".";
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result1 !== null) {
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result3 !== null) {
result2 = [];
while (result3 !== null) {
result2.push(result3);
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result2 = null;
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos2;
}
} else {
result1 = null;
pos = pos2;
}
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return parseFloat(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_hex() {
var result0;
if (/^[a-fA-F0-9]/.test(input.charAt(pos))) {
result0 = input.charAt(pos);
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("[a-fA-F0-9]");
}
}
return result0;
}
function parse_string() {
var result0, result1, result2, result3, result4, result5, result6, result7;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 34) {
result0 = "\"";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result0 !== null) {
result1 = [];
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
}
if (result1 !== null) {
if (input.charCodeAt(pos) === 34) {
result2 = "\"";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return JSON.parse(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_array() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("array", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_values() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_conditional();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, args) {
if (first != "") {
args.unshift(first);
}
return args;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_object() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_keyvalues();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("object", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalue() {
var result0, result1, result2, result3, result4;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_string();
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
if (input.charCodeAt(pos) === 58) {
result3 = ":";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result3 !== null) {
result4 = parse_conditional();
if (result4 !== null) {
result0 = [result0, result1, result2, result3, result4];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return [a, b];
})(pos0, result0[1], result0[4]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalues() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_keyvalue();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, rest) {
if (first) {
rest.unshift(first);
}
return rest;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_ref() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.substr(pos, 2) === "//") {
result0 = "//";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"//\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 36) {
result0 = "$";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"$\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "**") {
result0 = "**";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"**\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
}
}
}
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
e = expr(a);
if (b) {
b.args.unshift(e);
e = b;
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_id() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
result1 = [];
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return a.join('') + b.join('');
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_property() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("{}", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("[]", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_slashProperty() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_number();
if (result0 === null) {
result0 = parse_string();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("/", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(a, []);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_s() {
var result0, result1;
var pos0;
reportFailures++;
pos0 = pos;
result0 = [];
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
while (result1 !== null) {
result0.push(result1);
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
}
if (result0 !== null) {
result0 = (function(offset) {
return '';
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
reportFailures--;
if (reportFailures === 0 && result0 === null) {
matchFailed("space");
}
return result0;
}
function parse_path() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_root();
if (result0 !== null) {
result1 = [];
result2 = parse_step();
while (result2 !== null) {
result1.push(result2);
result2 = parse_step();
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_root() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_implicitDotRoot();
if (result0 !== null) {
result1 = parse_dotStep();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinPath(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_explicitDotRoot();
}
return result0;
}
function parse_step() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
result1 = parse_dotStep();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_noDotStep();
}
return result0;
}
function parse_implicitDotRoot() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("root");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 64) {
result0 = "@";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"@\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("this");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result2 !== null) {
result1 = [];
while (result2 !== null) {
result1.push(result2);
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
} else {
result1 = null;
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ancestor", [a.length]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_explicitDotRoot() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_dotStep() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_string();
if (result0 === null) {
result0 = parse_number();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("get", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_noDotStep() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("eval", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("pred", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("call", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function cleanupExpected(expected) {
expected.sort();
var lastExpected = null;
var cleanExpected = [];
for (var i = 0; i < expected.length; i++) {
if (expected[i] !== lastExpected) {
cleanExpected.push(expected[i]);
lastExpected = expected[i];
}
}
return cleanExpected;
}
function computeErrorPosition() {
/*
* The first idea was to use |String.split| to break the input up to the
* error position along newlines and derive the line and column from
* there. However IE's |split| implementation is so broken that it was
* enough to prevent it.
*/
var line = 1;
var column = 1;
var seenCR = false;
for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
var ch = input.charAt(i);
if (ch === "
") {
if (!seenCR) {
line++;
}
column = 1;
seenCR = false;
} else if (ch === "
" || ch === "\u2028" || ch === "\u2029") {
line++;
column = 1;
seenCR = true;
} else {
column++;
seenCR = false;
}
}
return {
line: line,
column: column
};
}
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e, array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++) array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
var result = parseFunctions[startRule]();
/*
* The parser is now in one of the following three states:
*
* 1. The parser successfully parsed the whole input.
*
* - |result !== null|
* - |pos === input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 2. The parser successfully parsed only a part of the input.
*
* - |result !== null|
* - |pos < input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 3. The parser did not successfully parse any part of the input.
*
* - |result === null|
* - |pos === 0|
* - |rightmostFailuresExpected| contains at least one failure
*
* All code following this comment (including called functions) must
* handle these states.
*/
if (result === null || pos !== input.length) {
var offset = Math.max(pos, rightmostFailuresPos);
var found = offset < input.length ? input.charAt(offset) : null;
var errorPosition = computeErrorPosition();
throw new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column);
}
return result;
},
toSource: function() {
return this._source;
},
SyntaxError: function(expected, found, offset, line, column) {
function buildMessage(expected, found) {
var expectedHumanized, foundHumanized;
switch (expected.length) {
case 0:
expectedHumanized = "end of input";
break;
case 1:
expectedHumanized = expected[0];
break;
default:
expectedHumanized = expected.slice(0, expected.length - 1).join(", ") + " or " + expected[expected.length - 1];
}
foundHumanized = found ? quote(found) : "end of input";
return "Expected " + expectedHumanized + " but " + foundHumanized + " found.";
}
this.name = "SyntaxError";
this.expected = expected;
this.found = found;
this.message = buildMessage(expected, found);
this.offset = offset;
this.line = line;
this.column = column;
}
},
name: "_parser",
path: "glass.Expression._parser",
namespace: "glass.Expression"
}
},
"glass.Expression": {
source: "constructor: (op, args) ->
@op = op
@args = args if args?
@
properties:
op:
type: 'string'
args:
type: 'array'
test: ->
return
peg = require 'pegjs'
fs = require 'fs'
parserSource = fs.readFileSync 'runtime/glass/Expression/_parser.pegjs', 'utf8'
parser = peg.buildParser parserSource
tests =
\"a.b.c\": {op:\"get\",args:[{op:\"get\",args:[{op:\"ref\",args:[\"a\"]},\"b\"]},\"c\"]}
\"a.1\": {op:\"get\",args:[{op:\"ref\",args:[\"a\"]},1]}
\"true\": true
\"false\": false
\"45.8\": 45.8
\"(45.8)\": 45.8
\"((45.8))\": 45.8
\"alpha\": {op:\"ref\",args:[\"alpha\"]}
\"35 + true * 2\": {op:\"+\", args:[35, {op:\"*\", args:[true,2]}]}
\" 5 * ( 2 + 2 ) \": {op:\"*\", args:[5, {op:\"+\", args:[2,2]}]}
\" ! ! true\": {op:\"!\",args:[{op:\"!\",args:[true]}]}
\"5 + -x\": {op:\"+\",args:[5,{op:\"-\",args:[{op:\"ref\",args:[\"x\"]}]}]}
\"true == 5 >= 2\": {op:\"==\",args:[true,{op:\">=\",args:[5,2]}]}
\"1 or 2 and 3\": {op:\"or\",args:[1,{op:\"and\",args:[2,3]}]}
\"1 ? 2 : 3\": {op:\"?:\",args:[1,2,3]}
\"1 ? 2 : 3 ? 4 : 5\" : {op:\"?:\",args:[1,2,{op:\"?:\",args:[3,4,5]}]}
\"a()(1,2)\" : {op:\"call\",args:[{op:\"call\",args:[{op:\"ref\",args:[\"a\"]},[]]},[1,2]]}
\"@\" : {op:\"this\"}
\"@foo\" : {op:\"get\",args:[{op:\"this\"},\"foo\"]}
'\"hello\"': \"hello\"
'\"\\\\t\\
\\
\\\\b\\\\\\\\foo\\\\\\/\"' : \"\\t
\\b\\\\foo\\/\"
\"[]\": {op:\"array\",args:[]}
\"[1,2]\": {op:\"array\",args:[1,2]}
\"[1+2]\": {op:\"array\",args:[{op:\"+\",args:[1,2]}]}
\"{}\": {op:\"object\",args:[]}
'{\"a\":2}': {op:\"object\",args:[[\"a\",2]]}
'{\"a\":2,\"b\":1+2}': {op:\"object\",args:[[\"a\",2],[\"b\",{op:\"+\",args:[1,2]}]]}
'@\"alpha\"': {op:\"get\",args:[{op:\"this\"},\"alpha\"]}
'*': {op:\"values\",args:[]}
'*.*': {op:\"values\",args:[{op:\"values\",args:[]}]}
\"foo.*\": {op:\"values\",args:[{op:\"ref\",args:[\"foo\"]}]}
\"..\": {op:\"ancestor\",args:[1]}
\"...\": {op:\"ancestor\",args:[2]}
\"@*{1+2}\": {op:\"eval\",args:[{op:\"values\",args:[{op:\"this\"}]},{op:\"+\",args:[1,2]}]}
\"/\": {op:\"root\"}
\"/foo\": {op:\"get\",args:[{op:\"root\"},\"foo\"]}
\"/*\": {op:\"values\",args:[{op:\"root\"}]}
for text, expected of tests
result = parser.parse text
if JSON.stringify(result) is JSON.stringify(expected)
console.log 'Pass: ' + text
else
console.log text, JSON.stringify result
return
",
input: "runtime\\glass\\Expression.coffee",
content: {
constructor: function(op, args) {
this.op = op;
if (args != null) {
this.args = args;
}
return this;
},
properties: {
op: {
type: "string",
name: "op",
writable: true
},
args: {
type: "array",
name: "args",
writable: true
}
},
test: function() {
var expected, fs, parser, parserSource, peg, result, tests, text;
return;
peg = require('pegjs');
fs = require('fs');
parserSource = fs.readFileSync('runtime/glass/Expression/_parser.pegjs', 'utf8');
parser = peg.buildParser(parserSource);
tests = {
"a.b.c": {
op: "get",
args: [{
op: "get",
args: [{
op: "ref",
args: ["a"]
},
"b"]
},
"c"]
},
"a.1": {
op: "get",
args: [{
op: "ref",
args: ["a"]
},
1]
},
"true": true,
"false": false,
"45.8": 45.8,
"(45.8)": 45.8,
"((45.8))": 45.8,
"alpha": {
op: "ref",
args: ["alpha"]
},
"35 + true * 2": {
op: "+",
args: [35, {
op: "*",
args: [true, 2]
}]
},
" 5 * ( 2 + 2 ) ": {
op: "*",
args: [5, {
op: "+",
args: [2, 2]
}]
},
" ! ! true": {
op: "!",
args: [{
op: "!",
args: [true]
}]
},
"5 + -x": {
op: "+",
args: [5, {
op: "-",
args: [{
op: "ref",
args: ["x"]
}]
}]
},
"true == 5 >= 2": {
op: "==",
args: [true, {
op: ">=",
args: [5, 2]
}]
},
"1 or 2 and 3": {
op: "or",
args: [1, {
op: "and",
args: [2, 3]
}]
},
"1 ? 2 : 3": {
op: "?:",
args: [1, 2, 3]
},
"1 ? 2 : 3 ? 4 : 5": {
op: "?:",
args: [1, 2, {
op: "?:",
args: [3, 4, 5]
}]
},
"a()(1,2)": {
op: "call",
args: [{
op: "call",
args: [{
op: "ref",
args: ["a"]
},
[]]
},
[1, 2]]
},
"@": {
op: "this"
},
"@foo": {
op: "get",
args: [{
op: "this"
},
"foo"]
},
'"hello"': "hello",
'"\\t
\\b\\\\foo\\\/"': "\t
\b\\foo\/",
"[]": {
op: "array",
args: []
},
"[1,2]": {
op: "array",
args: [1, 2]
},
"[1+2]": {
op: "array",
args: [{
op: "+",
args: [1, 2]
}]
},
"{}": {
op: "object",
args: []
},
'{"a":2}': {
op: "object",
args: [["a", 2]]
},
'{"a":2,"b":1+2}': {
op: "object",
args: [["a", 2], ["b", {
op: "+",
args: [1, 2]
}]]
},
'@"alpha"': {
op: "get",
args: [{
op: "this"
},
"alpha"]
},
'*': {
op: "values",
args: []
},
'*.*': {
op: "values",
args: [{
op: "values",
args: []
}]
},
"foo.*": {
op: "values",
args: [{
op: "ref",
args: ["foo"]
}]
},
"..": {
op: "ancestor",
args: [1]
},
"...": {
op: "ancestor",
args: [2]
},
"@*{1+2}": {
op: "eval",
args: [{
op: "values",
args: [{
op: "this"
}]
},
{
op: "+",
args: [1, 2]
}]
},
"/": {
op: "root"
},
"/foo": {
op: "get",
args: [{
op: "root"
},
"foo"]
},
"/*": {
op: "values",
args: [{
op: "root"
}]
}
};
for (text in tests) {
expected = tests[text];
result = parser.parse(text);
if (JSON.stringify(result) === JSON.stringify(expected)) {
console.log('Pass: ' + text);
} else {
console.log(text, JSON.stringify(result));
}
}
},
name: "Expression",
path: "glass.Expression",
namespace: "glass"
}
},
"glass.JSONMergePatch": {
source: "
# applies a patch to the target object and returns the resulting target
apply: (target, patch) ->
if target? and target isnt patch and isPlainObject(patch) and not isPrimitive(target)
for key, value of patch
if value is undefined
delete target[key]
else
target[key] = apply target[key], patch[key]
return target
else
return patch
# (path1, path2, path3.., patch) ->
create: ->
if arguments.length is 1
return arguments[0]
result = {}
current = result
for arg, i in arguments when i + 1 < arguments.length
last = i + 2 is arguments.length
current = current[arg] = if last then arguments[arguments.length-1] else {}
result
test: ->
assertEquals {a:{b:12}}, create 'a', 'b', 12
assertEquals {a:3}, apply({a:1,b:2}, {a:3,b:undefined})
",
input: "runtime\\glass\\JSONMergePatch.coffee",
content: {
apply: function(target, patch) {
var key, value;
if ((target != null) && target !== patch && isPlainObject(patch) && !isPrimitive(target)) {
for (key in patch) {
value = patch[key];
if (value === void 0) {
delete target[key];
} else {
target[key] = apply(target[key], patch[key]);
}
}
return target;
} else {
return patch;
}
},
create: function() {
var arg, current, i, last, result, _i, _len;
if (arguments.length === 1) {
return arguments[0];
}
result = {};
current = result;
for (i = _i = 0, _len = arguments.length; _i < _len; i = ++_i) {
arg = arguments[i];
if (! (i + 1 < arguments.length)) {
continue;
}
last = i + 2 === arguments.length;
current = current[arg] = last ? arguments[arguments.length - 1] : {};
}
return result;
},
test: function() {
assertEquals({
a: {
b: 12
}
},
create('a', 'b', 12));
return assertEquals({
a: 3
},
apply({
a: 1,
b: 2
},
{
a: 3,
b: void 0
}));
},
name: "JSONMergePatch",
path: "glass.JSONMergePatch",
namespace: "glass"
}
},
"glass.JSONPointer": {
source: "# json pointer implementation as per
# http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-05
_decodeStep: (step) -> step.replace(/~1/g, '/').replace(/~0/g, '~')
_getLastStep: (pointer) ->
_decodeStep pointer.substring(pointer.lastIndexOf('/') + 1)
_getParent: (pointer) ->
if not pointer?.length
null
else
pointer.substring(0, pointer.lastIndexOf('/'))
toArray: (pointer) ->
for step in pointer.substring(1).split('/')
_decodeStep step
get: (doc, pointer) ->
value = doc
if pointer.length
path = toArray pointer
for step in path when value?
value = value[step]
value
set: (doc, pointer, value) ->
parentPointer = _getParent pointer
if parentPointer?
parent = get doc, parentPointer
lastStep = _getLastStep pointer
parent[lastStep] = value
value
test: ->
assertEquals _getParent(\"/a/b/c\"), \"/a/b\"
assertEquals _getParent(\"/a\"), \"\"
assertEquals _getParent(\"\"), null
assertEquals _getLastStep(\"/a/b/c\"), \"c\"
assertEquals _getLastStep(\"/a~0~1\"), \"a~/\"
assertEquals _getLastStep(\"\"), \"\"
# tests as per spec
doc = {
\"foo\": [\"bar\", \"baz\"],
\"\": 0,
\"a/b\": 1,
\"c%d\": 2,
\"e^f\": 3,
\"g|h\": 4,
\"i\\\\j\": 5,
\"k\\\"l\": 6,
\" \": 7,
\"m~n\": 8
}
assertEquals get(doc, \"\"), doc
assertEquals get(doc, \"/foo\"), [\"bar\", \"baz\"]
assertEquals get(doc, \"/foo/0\"), \"bar\"
assertEquals get(doc, \"/\"), 0
assertEquals get(doc, \"/a~1b\"), 1
assertEquals get(doc, \"/c%d\"), 2
assertEquals get(doc, \"/e^f\"), 3
assertEquals get(doc, \"/g|h\"), 4
assertEquals get(doc, \"/i\\\\j\"), 5
assertEquals get(doc, \"/k\\\"l\"), 6
assertEquals get(doc, \"/ \"), 7
assertEquals get(doc, \"/m~0n\"), 8
# now test set
assertEquals set(doc, \"/\", 10), 10
assertEquals doc[\"\"], 10
assertEquals set(doc, \"/foo/0\", 10), 10
assertEquals doc.foo[0], 10",
input: "runtime\\glass\\JSONPointer.coffee",
content: {
toArray: function(pointer) {
var step, _i, _len, _ref, _results;
_ref = pointer.substring(1).split('/');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
step = _ref[_i];
_results.push(_decodeStep(step));
}
return _results;
},
get: function(doc, pointer) {
var path, step, value, _i, _len;
value = doc;
if (pointer.length) {
path = toArray(pointer);
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
}
return value;
},
set: function(doc, pointer, value) {
var lastStep, parent, parentPointer;
parentPointer = _getParent(pointer);
if (parentPointer != null) {
parent = get(doc, parentPointer);
lastStep = _getLastStep(pointer);
parent[lastStep] = value;
}
return value;
},
test: function() {
var doc;
assertEquals(_getParent("/a/b/c"), "/a/b");
assertEquals(_getParent("/a"), "");
assertEquals(_getParent(""), null);
assertEquals(_getLastStep("/a/b/c"), "c");
assertEquals(_getLastStep("/a~0~1"), "a~/");
assertEquals(_getLastStep(""), "");
doc = {
"foo": ["bar", "baz"],
"": 0,
"a/b": 1,
"c%d": 2,
"e^f": 3,
"g|h": 4,
"i\\j": 5,
"k\"l": 6,
" ": 7,
"m~n": 8
};
assertEquals(get(doc, ""), doc);
assertEquals(get(doc, "/foo"), ["bar", "baz"]);
assertEquals(get(doc, "/foo/0"), "bar");
assertEquals(get(doc, "/"), 0);
assertEquals(get(doc, "/a~1b"), 1);
assertEquals(get(doc, "/c%d"), 2);
assertEquals(get(doc, "/e^f"), 3);
assertEquals(get(doc, "/g|h"), 4);
assertEquals(get(doc, "/i\\j"), 5);
assertEquals(get(doc, "/k\"l"), 6);
assertEquals(get(doc, "/ "), 7);
assertEquals(get(doc, "/m~0n"), 8);
assertEquals(set(doc, "/", 10), 10);
assertEquals(doc[""], 10);
assertEquals(set(doc, "/foo/0", 10), 10);
return assertEquals(doc.foo[0], 10);
},
name: "JSONPointer",
path: "glass.JSONPointer",
namespace: "glass"
}
},
"glass.Observable": {
source: "properties:
is: (type) -> @constructor.implements[type.path ? type] is true
watchers:
serializable: false
watch: (property, watcher) ->
if isFunction property
watcher = property
property = ''
id = getId watcher
@patch 'watchers', property, id, watcher
# returns a function which will remove the watch
=> @patch 'watchers', property, getId(watcher), undefined
patch: (change) ->
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
try
JSONMergePatch.apply this, change
catch e
console.log e
finally
@notify change
return
notify: (change) ->
if @watchers?
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
for property, watchers of @watchers
if property.length is 0 or change.hasOwnProperty property
changeArg = if property.length is 0 then change else change[property]
for id, watcher of watchers
watcher this, changeArg
return
toJSON: ->
values =
class: @constructor.path
# serialize statically defined properties
for name, property of @constructor.properties
value = @[name]
if property.serializable isnt false and not isFunction(value)
values[name] = value
# serialize custom properties if allowed by schema
if @constructor.additionalProperties isnt false
for own name, value of @ when not isPrivate name
values[name] = value
values
toString: -> @toJSON()
test:
toJSON: ->
# I need this test later
# on a class that actually has serializable properties
a = new Observable
a.x = 12
a.y = ->
a.z = true
assertEquals a, {class:'glass.Observable', x:12,z:true}
watchAll: ->
# we should actually be able to watch ourselves get added to watchers
# this is very meta.
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch watcher
# now make sure we were called with our own watcher
assert watchArgs[0] is a
assert watchArgs[1]?.watchers?[\"\"]?
# reset watchArgs, and watch something else
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assertEquals a.a, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {a:{b:3}}
# now unwatch
unwatch()
# make sure universal watcher is now empty
assertEquals a.watchers[\"\"], {}
# now reset and do a new event, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
watchProperty: ->
# watch a property
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch \"foo\", watcher
# now make sure we were not called
assert watchArgs.length is 0
# reset watchArgs, and watch something else
a.patch \"foo\", \"b\", 3
assertEquals a.foo, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {b:3}
# now reset and do a different property, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
# now unwatch
unwatch()
# make sure we no longer see foo
watchArgs.length = 0
a.patch \"foo\", \"b\", 4
assert watchArgs.length is 0
",
input: "runtime\\glass\\Observable.coffee",
content: {
properties: {
is: {
value: function(type) {
var _ref;
return this.constructor["implements"][(_ref = type.path) != null ? _ref: type] === true;
},
name: "is"
},
watchers: {
serializable: false,
name: "watchers",
writable: true
},
watch: {
value: function(property, watcher) {
var id, _this = this;
if (isFunction(property)) {
watcher = property;
property = '';
}
id = getId(watcher);
this.patch('watchers', property, id, watcher);
return function() {
return _this.patch('watchers', property, getId(watcher), void 0);
};
},
name: "watch"
},
patch: {
value: function(change) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
try {
JSONMergePatch.apply(this, change);
} catch(e) {
console.log(e);
} finally {
this.notify(change);
}
},
name: "patch"
},
notify: {
value: function(change) {
var changeArg, id, property, watcher, watchers, _ref;
if (this.watchers != null) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
_ref = this.watchers;
for (property in _ref) {
watchers = _ref[property];
if (property.length === 0 || change.hasOwnProperty(property)) {
changeArg = property.length === 0 ? change: change[property];
for (id in watchers) {
watcher = watchers[id];
watcher(this, changeArg);
}
}
}
}
},
name: "notify"
},
toJSON: {
value: function() {
var name, property, value, values, _ref;
values = {
"class": this.constructor.path
};
_ref = this.constructor.properties;
for (name in _ref) {
property = _ref[name];
value = this[name];
if (property.serializable !== false && !isFunction(value)) {
values[name] = value;
}
}
if (this.constructor.additionalProperties !== false) {
for (name in this) {
if (!__hasProp.call(this, name)) continue;
value = this[name];
if (!isPrivate(name)) {
values[name] = value;
}
}
}
return values;
},
name: "toJSON"
},
toString: {
value: function() {
return this.toJSON();
},
name: "toString"
}
},
test: {
toJSON: function() {
var a;
a = new Observable;
a.x = 12;
a.y = function() {};
a.z = true;
return assertEquals(a, {
"class": 'glass.Observable',
x: 12,
z: true
});
},
watchAll: function() {
var a, unwatch, watchArgs, watcher, _ref, _ref1;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch(watcher);
assert(watchArgs[0] === a);
assert(((_ref = watchArgs[1]) != null ? (_ref1 = _ref.watchers) != null ? _ref1[""] : void 0 : void 0) != null);
watchArgs.length = 0;
a.patch("a", "b", 3);
assertEquals(a.a, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
a: {
b: 3
}
});
unwatch();
assertEquals(a.watchers[""], {});
watchArgs.length = 0;
a.patch("a", "b", 3);
return assert(watchArgs.length === 0);
},
watchProperty: function() {
var a, unwatch, watchArgs, watcher;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch("foo", watcher);
assert(watchArgs.length === 0);
a.patch("foo", "b", 3);
assertEquals(a.foo, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
b: 3
});
watchArgs.length = 0;
a.patch("a", "b", 3);
assert(watchArgs.length === 0);
unwatch();
watchArgs.length = 0;
a.patch("foo", "b", 4);
return assert(watchArgs.length === 0);
}
},
name: "Observable",
path: "glass.Observable",
namespace: "glass"
}
},
glass: {
source: "require:
\tString: true
# runtime type tests
isFunction: (object) -> object? and typeof object is 'function'
isString: (object) -> object?.constructor is String
isArray: (object) -> Array.isArray object
isBoolean: (object) -> object? and typeof object is 'boolean'
isNumber: (object) -> object? and typeof object is 'number'
isObject: (object) -> typeof object is 'object'
isPlainObject: (object) -> object?.constructor is Object
isPrototype: (object) -> object? and object is object.constructor.prototype
isDate: (object) -> object?.constructor is Date
isPrimitive: (object) -> isString(object) or isBoolean(object) or isNumber(object) or isDate(object)
isPrivate: (property) -> property?[0] is '_'
# generic utility functions
values: (object) -> (value for key, value of object)
# generic patch method, uses patch method built into object if present
patch: (target, pathAndPatch...) ->
patch = JSONMergePatch.create.apply null, pathAndPatch
if isFunction target?.patch
target.patch patch
else
glass.JSONMergePatch.apply target, patch
# testing assertions
_getStackLocationInfo: (e, depth) ->
line = e.stack?.split('
')[depth]
return null unless line?
match = /\\(([\\w\\W]*?):(\\d+):(\\d+)\\)/.exec line
return {
file: match[1]
line: parseInt match[2]
column: parseInt match[3]
}
_throwAssertionFailure: (message) ->
try
throw new Error \"Assertion failed: \" + message
catch e
info = _getStackLocationInfo e, 3
if info?
_dumpFile info.file, info.line - 2, info.line + 2, info.line
throw e
_dumpFile: (file, from=1, to, highlight) ->
fs = require 'fs'
return unless fs?
try
content = fs.readFileSync(file).toString()
catch e
content = \"Source not found: #{e}\"
console.log '------------------------------------------------'
console.log file
console.log '------------------------------------------------'
number = 1
if content?
lines = content.split /
|
/
to ?= lines.length
for line in lines
lineNumber = number++
if lineNumber >= from and lineNumber <= to
num = String lineNumber
while num.length < 3
num += ' '
if lineNumber is highlight
`console.log(\"\\033[91m\" + num + \": \" + line + \"\\033[0m\");`
else
`console.log(num + \": \" + line);`
console.log '------------------------------------------------'
assert: (a) ->
_throwAssertionFailure JSON.stringify(a) unless a
assertTrue: (a) ->
_throwAssertionFailure JSON.stringify(a) + \" != true\" unless a is true
assertEquals: (a, b) ->
if JSON.stringify(a) isnt JSON.stringify(b)
_throwAssertionFailure JSON.stringify(a) + ' != ' + JSON.stringify(b)
# gets a unique string identifier for any object
getId:
do: ->
counter = 0
(a) ->
if a is null
return '__null__'
if a is undefined
return '__undefined__'
if typeof a is 'object' or typeof a is 'function'
return a.id ?= '__' + (counter++) + '__'
# 12 == \"12\" under this technique
return a.toString()
getType: (path) ->
array = if isArray path then path else path.split '.'
value = global
for step in path when value?
value = value[step]
throw new Error \"Type not found: #{path}\" unless isFunction value
value
test:
values: ->
assertEquals values({a:1,b:3,c:2}), [1,3,2]
patch: ->
x = {a:{foo:1,bar:3},b:2}
patch x, 'a', 'foo', 5
assertEquals x.a.foo, 5
",
input: "runtime\\glass.coffee",
content: {
require: {
String: true
},
isFunction: function(object) {
return (object != null) && typeof object === 'function';
},
isString: function(object) {
return (object != null ? object.constructor: void 0) === String;
},
isArray: function(object) {
return Array.isArray(object);
},
isBoolean: function(object) {
return (object != null) && typeof object === 'boolean';
},
isNumber: function(object) {
return (object != null) && typeof object === 'number';
},
isObject: function(object) {
return typeof object === 'object';
},
isPlainObject: function(object) {
return (object != null ? object.constructor: void 0) === Object;
},
isPrototype: function(object) {
return (object != null) && object === object.constructor.prototype;
},
isDate: function(object) {
return (object != null ? object.constructor: void 0) === Date;
},
isPrimitive: function(object) {
return isString(object) || isBoolean(object) || isNumber(object) || isDate(object);
},
isPrivate: function(property) {
return (property != null ? property[0] : void 0) === '_';
},
values: function(object) {
var key, value, _results;
_results = [];
for (key in object) {
value = object[key];
_results.push(value);
}
return _results;
},
patch: function() {
var patch, pathAndPatch, target;
target = arguments[0],
pathAndPatch = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
patch = JSONMergePatch.create.apply(null, pathAndPatch);
if (isFunction(target != null ? target.patch: void 0)) {
return target.patch(patch);
} else {
return glass.JSONMergePatch.apply(target, patch);
}
},
assert: function(a) {
if (!a) {
return _throwAssertionFailure(JSON.stringify(a));
}
},
assertTrue: function(a) {
if (a !== true) {
return _throwAssertionFailure(JSON.stringify(a) + " != true");
}
},
assertEquals: function(a, b) {
if (JSON.stringify(a) !== JSON.stringify(b)) {
return _throwAssertionFailure(JSON.stringify(a) + ' != ' + JSON.stringify(b));
}
},
getId: {
do: function() {
var counter;
counter = 0;
return function(a) {
var _ref;
if (a === null) {
return '__null__';
}
if (a === void 0) {
return '__undefined__';
}
if (typeof a === 'object' || typeof a === 'function') {
return (_ref = a.id) != null ? _ref: a.id = '__' + (counter++) + '__';
}
return a.toString();
};
}
},
getType: function(path) {
var array, step, value, _i, _len;
array = isArray(path) ? path: path.split('.');
value = global;
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
if (!isFunction(value)) {
throw new Error("Type not found: " + path);
}
return value;
},
test: {
values: function() {
return assertEquals(values({
a: 1,
b: 3,
c: 2
}), [1, 3, 2]);
},
patch: function() {
var x;
x = {
a: {
foo: 1,
bar: 3
},
b: 2
};
patch(x, 'a', 'foo', 5);
return assertEquals(x.a.foo, 5);
}
},
name: "glass",
path: "glass",
namespace: ""
}
},
String: {
source: "extension: true
properties:
\tstartsWith: (s) -> @slice(0,s.length) is s
\tendsWith: (s) -> @slice(-s.length) is s
\tcontains: (s) -> @indexOf(s) >= 0
\ttoArray: () -> @split ''",
input: "runtime\\String.coffee",
content: {
extension: true,
properties: {
startsWith: {
value: function(s) {
return this.slice(0, s.length) === s;
},
name: "startsWith"
},
endsWith: {
value: function(s) {
return this.slice( - s.length) === s;
},
name: "endsWith"
},
contains: {
value: function(s) {
return this.indexOf(s) >= 0;
},
name: "contains"
},
toArray: {
value: function() {
return this.split('');
},
name: "toArray"
}
},
name: "String",
path: "String",
namespace: ""
}
}
}
} | {
options: {
input: {
dir: "runtime",
match: /\.(coffee|pegjs)$/
},
output: {
dir: "www/js"
},
script: {
includes: "www/includes.html",
prefix: "/js/"
},
module: {
main: "glass.js",
prefix: "./www/js/"
},
debug: "buildlog.html",
test: "glass.allTests",
addon: {
pregenerate: {
addUri: function(schema) {
var content, type, typeName, _ref2, _ref3;
_ref2 = schema.types;
for (typeName in _ref2) {
type = _ref2[typeName];
content = type.content;
if (content.extension) {
continue;
}
if ((_ref3 = content.uri) == null) {
content.uri = "global:/" + (content.path.replace(/\./g, '/'));
}
}
return schema;
}
}
},
namespace: ""
},
types: {
"glass.Component": {
source: "extends: 'Observable'
constructor: (properties) ->
@patch properties
# now site ourselves on our parent
if @parent
id = getId @
patch @parent, id, @
@
properties:
id:
description: 'string which uniquely identifies this component within its parent'
type: 'string'
parent:
description: 'the object that contains this component'
serializable: false
type: 'object'
disposed: false
dispose: -> @patch 'disposed', true
notify: (change) ->
Observable.prototype.notify.apply this, arguments
if change?.disposed
# dispose of any disposable children
for id, child of @ when child?.parent is @
child.dispose?()
# remove self from parent
if @id and @parent
patch @parent, @id, undefined
return
test:
lifecycle: ->
parent = new Component
assert not parent.id?
assert not parent.parent?
child = new Component parent:parent
# id should be automatically assigned
assert isString child.id
assert parent is child.parent
assert parent[child.id] is child
assert parent.hasOwnProperty child.id
parent.dispose()
assert child.disposed is true
assert not parent.hasOwnProperty child.id
nonEnumerability: ->
visibleKeys = (key for key of new Component)
assertEquals visibleKeys, []",
input: "runtime\\glass\\Component.coffee",
content: {
extends: ["glass.Observable"],
constructor: function(properties) {
var id;
this.patch(properties);
if (this.parent) {
id = getId(this);
patch(this.parent, id, this);
}
return this;
},
properties: {
id: {
description: "string which uniquely identifies this component within its parent",
type: "string",
name: "id",
writable: true
},
parent: {
description: "the object that contains this component",
serializable: false,
type: "object",
name: "parent",
writable: true
},
disposed: {
value: false,
name: "disposed",
writable: true
},
dispose: {
value: function() {
return this.patch('disposed', true);
},
name: "dispose"
},
notify: {
value: function(change) {
var child, id;
Observable.prototype.notify.apply(this, arguments);
if (change != null ? change.disposed: void 0) {
for (id in this) {
child = this[id];
if ((child != null ? child.parent: void 0) === this) {
if (typeof child.dispose === "function") {
child.dispose();
}
}
}
if (this.id && this.parent) {
patch(this.parent, this.id, void 0);
}
}
},
name: "notify"
}
},
test: {
lifecycle: function() {
var child, parent;
parent = new Component;
assert(!(parent.id != null));
assert(!(parent.parent != null));
child = new Component({
parent: parent
});
assert(isString(child.id));
assert(parent === child.parent);
assert(parent[child.id] === child);
assert(parent.hasOwnProperty(child.id));
parent.dispose();
assert(child.disposed === true);
return assert(!parent.hasOwnProperty(child.id));
},
nonEnumerability: function() {
var key, visibleKeys;
visibleKeys = (function() {
var _results;
_results = [];
for (key in new Component) {
_results.push(key);
}
return _results;
})();
return assertEquals(visibleKeys, []);
}
},
name: "Component",
path: "glass.Component",
namespace: "glass"
}
},
"glass.Container": {
source: "extends: 'Observable'
properties:
watch: ->
unwatch: ->
",
input: "runtime\\glass\\Container.coffee",
content: {
extends: ["glass.Observable"],
properties: {
watch: {
value: function() {},
name: "watch"
},
unwatch: {
value: function() {},
name: "unwatch"
}
},
name: "Container",
path: "glass.Container",
namespace: "glass"
}
},
"glass.Expression._parser": {
source: "{
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e,array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++)
array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
}
start = expression
expression = conditional
conditional = e:or args:(\"?\" b:expression \":\" c:expression {return [b,c];})* {
while (args.length > 0) {
e = expr(\"?:\", [e].concat(args.pop()));
}
return e;
}
or = a:and b:((\"or\") and)* { return joinLeft(a,b); }
and = a:equality b:((\"and\") equality)* { return joinLeft(a,b); }
equality = a:rel b:((\"==\" / \"!=\") rel)* { return joinLeft(a,b); }
rel = a:sum b:((\"<=\" / \">=\" / \"<\" / \">\") sum)* { return joinLeft(a,b); }
sum = a:product b:((\"+\" / \"-\") product)* { return joinLeft(a,b); }
product = a:not b:((\"*\" / \"div\" / \"mod\") not)* { return joinLeft(a,b); }
not = ops:(s op:(\"!\" / \"~\" / \"+\" / \"-\") { return op; })* b:primary { return unaryRight(ops,b); }
primary = s a:(group / literal / path) s { return a; }
group = \"(\" a:expression \")\" { return a; }
literal = s a:(boolean / number / string / array / object) s { return a; }
boolean = a:(\"true\" / \"false\") { return a == \"true\"; }
number = a:([0-9]+ (\".\" [0-9]+)?) { return parseFloat(toString(a)); }
hex = [a-fA-F0-9]
// as per JSON http://www.json.org
string = a:( '\"' (
[\\u0000-\\u0021\\u0023-\\u005c\\u005e-\\uffff] // all unicode chars except \\ and \"
/ (\"\\\\\" (\"\\\"\" / \"\\\\\" / \"\\/\" / \"b\" / \"f\" / \"n\" / \"r\" / \"t\" / (\"u\" hex hex hex hex)))
)* '\"' )
{ return JSON.parse(toString(a)); }
array = \"[\" a:values \"]\" { return expr(\"array\", a); }
values = first:expression? args:(\",\" b:expression {return b;})* {
if (first != \"\") { args.unshift(first); } return args;
}
object = \"{\" a:keyvalues \"}\" { return expr(\"object\", a); }
keyvalue = s a:string s \":\" b:expression { return [a,b]; }
keyvalues = first:keyvalue? rest:(\",\" b:keyvalue {return b;})* {
if (first) { rest.unshift(first); } return rest;
}
ref = a:(\"//\" / \"/\" / \"$\" / \"**\" / \"*\" / \"..\" / \".\") b:slashProperty? {
e = expr(a); if (b) { b.args.unshift(e); e = b; } return e;
}
/ a:id { return expr(\"ref\", [a]); }
id = a:[a-z_]+ b:[a-z_0-9]* { return a.join('') + b.join(''); }
property = \"/\" a:slashProperty { return a; }
/ \"{\" a:expression \"}\" { return expr(\"{}\", [a]); } // locally scoped expression
/ \"[\" a:expression \"]\" { return expr(\"[]\", [a]); } // predicate
slashProperty = a:(id/number/string) { return expr(\"/\", [a]); }
/ a:(\"..\" / \"*\") { return expr(a, []); }
s \"space\" = [ ]* { return ''; }
path = a:root b:step* {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
}
root = a:implicitDotRoot b:dotStep? { return joinPath(a,b); }
/ explicitDotRoot
step = \".\" a:dotStep { return a; }
/ noDotStep
implicitDotRoot = \"/\" { return expr(\"root\"); }
/ \"@\" { return expr(\"this\"); }
/ \".\" a:\".\"+ { return expr(\"ancestor\", [a.length]); }
explicitDotRoot = a:id { return expr(\"ref\", [a]); }
/ \"*\" { return expr(\"values\", []); }
dotStep = a:(id / string / number) { return expr(\"get\", [a]); }
/ \"*\" { return expr(\"values\", []); }
noDotStep = \"{\" a:expression \"}\" { return expr(\"eval\", [a]); }
/ \"[\" a:expression \"]\" { return expr(\"pred\", [a]); }
/ \"(\" a:values \")\" { return expr(\"call\", [a]); }
",
input: "runtime\\glass\\Expression\\_parser.pegjs",
content: {
value: {
parse: function(input, startRule) {
var parseFunctions = {
"conditional": parse_conditional,
"or": parse_or,
"and": parse_and,
"equality": parse_equality,
"rel": parse_rel,
"sum": parse_sum,
"product": parse_product,
"not": parse_not,
"primary": parse_primary,
"group": parse_group,
"literal": parse_literal,
"boolean": parse_boolean,
"number": parse_number,
"hex": parse_hex,
"string": parse_string,
"array": parse_array,
"values": parse_values,
"object": parse_object,
"keyvalue": parse_keyvalue,
"keyvalues": parse_keyvalues,
"ref": parse_ref,
"id": parse_id,
"property": parse_property,
"slashProperty": parse_slashProperty,
"s": parse_s,
"path": parse_path,
"root": parse_root,
"step": parse_step,
"implicitDotRoot": parse_implicitDotRoot,
"explicitDotRoot": parse_explicitDotRoot,
"dotStep": parse_dotStep,
"noDotStep": parse_noDotStep
};
if (startRule !== undefined) {
if (parseFunctions[startRule] === undefined) {
throw new Error("Invalid rule name: " + quote(startRule) + ".");
}
} else {
startRule = "conditional";
}
var pos = 0;
var reportFailures = 0;
var rightmostFailuresPos = 0;
var rightmostFailuresExpected = [];
function padLeft(input, padding, length) {
var result = input;
var padLength = length - input.length;
for (var i = 0; i < padLength; i++) {
result = padding + result;
}
return result;
}
function escape(ch) {
var charCode = ch.charCodeAt(0);
var escapeChar;
var length;
if (charCode <= 0xFF) {
escapeChar = 'x';
length = 2;
} else {
escapeChar = 'u';
length = 4;
}
return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
}
function matchFailed(failure) {
if (pos < rightmostFailuresPos) {
return;
}
if (pos > rightmostFailuresPos) {
rightmostFailuresPos = pos;
rightmostFailuresExpected = [];
}
rightmostFailuresExpected.push(failure);
}
function parse_conditional() {
var result0, result1, result2, result3, result4, result5;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_or();
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, e, args) {
while (args.length > 0) {
e = expr("?:", [e].concat(args.pop()));
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_or() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_and();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_and() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_equality();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_equality() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_rel();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_rel() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_sum();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_sum() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_product();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_product() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_not();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_not() {
var result0, result1, result2;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = [];
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
while (result1 !== null) {
result0.push(result1);
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
}
if (result0 !== null) {
result1 = parse_primary();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, ops, b) {
return unaryRight(ops, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_primary() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_group();
if (result1 === null) {
result1 = parse_literal();
if (result1 === null) {
result1 = parse_path();
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_group() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_literal() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_boolean();
if (result1 === null) {
result1 = parse_number();
if (result1 === null) {
result1 = parse_string();
if (result1 === null) {
result1 = parse_array();
if (result1 === null) {
result1 = parse_object();
}
}
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_boolean() {
var result0;
var pos0;
pos0 = pos;
if (input.substr(pos, 4) === "true") {
result0 = "true";
pos += 4;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"true\"");
}
}
if (result0 === null) {
if (input.substr(pos, 5) === "false") {
result0 = "false";
pos += 5;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"false\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a == "true";
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_number() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
pos2 = pos;
if (input.charCodeAt(pos) === 46) {
result1 = ".";
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result1 !== null) {
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result3 !== null) {
result2 = [];
while (result3 !== null) {
result2.push(result3);
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result2 = null;
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos2;
}
} else {
result1 = null;
pos = pos2;
}
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return parseFloat(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_hex() {
var result0;
if (/^[a-fA-F0-9]/.test(input.charAt(pos))) {
result0 = input.charAt(pos);
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("[a-fA-F0-9]");
}
}
return result0;
}
function parse_string() {
var result0, result1, result2, result3, result4, result5, result6, result7;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 34) {
result0 = "\"";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result0 !== null) {
result1 = [];
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
}
if (result1 !== null) {
if (input.charCodeAt(pos) === 34) {
result2 = "\"";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return JSON.parse(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_array() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("array", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_values() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_conditional();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, args) {
if (first != "") {
args.unshift(first);
}
return args;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_object() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_keyvalues();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("object", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalue() {
var result0, result1, result2, result3, result4;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_string();
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
if (input.charCodeAt(pos) === 58) {
result3 = ":";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result3 !== null) {
result4 = parse_conditional();
if (result4 !== null) {
result0 = [result0, result1, result2, result3, result4];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return [a, b];
})(pos0, result0[1], result0[4]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalues() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_keyvalue();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, rest) {
if (first) {
rest.unshift(first);
}
return rest;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_ref() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.substr(pos, 2) === "//") {
result0 = "//";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"//\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 36) {
result0 = "$";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"$\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "**") {
result0 = "**";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"**\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
}
}
}
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
e = expr(a);
if (b) {
b.args.unshift(e);
e = b;
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_id() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
result1 = [];
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return a.join('') + b.join('');
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_property() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("{}", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("[]", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_slashProperty() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_number();
if (result0 === null) {
result0 = parse_string();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("/", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(a, []);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_s() {
var result0, result1;
var pos0;
reportFailures++;
pos0 = pos;
result0 = [];
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
while (result1 !== null) {
result0.push(result1);
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
}
if (result0 !== null) {
result0 = (function(offset) {
return '';
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
reportFailures--;
if (reportFailures === 0 && result0 === null) {
matchFailed("space");
}
return result0;
}
function parse_path() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_root();
if (result0 !== null) {
result1 = [];
result2 = parse_step();
while (result2 !== null) {
result1.push(result2);
result2 = parse_step();
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_root() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_implicitDotRoot();
if (result0 !== null) {
result1 = parse_dotStep();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinPath(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_explicitDotRoot();
}
return result0;
}
function parse_step() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
result1 = parse_dotStep();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_noDotStep();
}
return result0;
}
function parse_implicitDotRoot() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("root");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 64) {
result0 = "@";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"@\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("this");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result2 !== null) {
result1 = [];
while (result2 !== null) {
result1.push(result2);
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
} else {
result1 = null;
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ancestor", [a.length]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_explicitDotRoot() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_dotStep() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_string();
if (result0 === null) {
result0 = parse_number();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("get", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_noDotStep() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("eval", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("pred", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("call", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function cleanupExpected(expected) {
expected.sort();
var lastExpected = null;
var cleanExpected = [];
for (var i = 0; i < expected.length; i++) {
if (expected[i] !== lastExpected) {
cleanExpected.push(expected[i]);
lastExpected = expected[i];
}
}
return cleanExpected;
}
function computeErrorPosition() {
/*
* The first idea was to use |String.split| to break the input up to the
* error position along newlines and derive the line and column from
* there. However IE's |split| implementation is so broken that it was
* enough to prevent it.
*/
var line = 1;
var column = 1;
var seenCR = false;
for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
var ch = input.charAt(i);
if (ch === "
") {
if (!seenCR) {
line++;
}
column = 1;
seenCR = false;
} else if (ch === "
" || ch === "\u2028" || ch === "\u2029") {
line++;
column = 1;
seenCR = true;
} else {
column++;
seenCR = false;
}
}
return {
line: line,
column: column
};
}
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e, array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++) array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
var result = parseFunctions[startRule]();
/*
* The parser is now in one of the following three states:
*
* 1. The parser successfully parsed the whole input.
*
* - |result !== null|
* - |pos === input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 2. The parser successfully parsed only a part of the input.
*
* - |result !== null|
* - |pos < input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 3. The parser did not successfully parse any part of the input.
*
* - |result === null|
* - |pos === 0|
* - |rightmostFailuresExpected| contains at least one failure
*
* All code following this comment (including called functions) must
* handle these states.
*/
if (result === null || pos !== input.length) {
var offset = Math.max(pos, rightmostFailuresPos);
var found = offset < input.length ? input.charAt(offset) : null;
var errorPosition = computeErrorPosition();
throw new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column);
}
return result;
},
toSource: function() {
return this._source;
},
SyntaxError: function(expected, found, offset, line, column) {
function buildMessage(expected, found) {
var expectedHumanized, foundHumanized;
switch (expected.length) {
case 0:
expectedHumanized = "end of input";
break;
case 1:
expectedHumanized = expected[0];
break;
default:
expectedHumanized = expected.slice(0, expected.length - 1).join(", ") + " or " + expected[expected.length - 1];
}
foundHumanized = found ? quote(found) : "end of input";
return "Expected " + expectedHumanized + " but " + foundHumanized + " found.";
}
this.name = "SyntaxError";
this.expected = expected;
this.found = found;
this.message = buildMessage(expected, found);
this.offset = offset;
this.line = line;
this.column = column;
}
},
name: "_parser",
path: "glass.Expression._parser",
namespace: "glass.Expression"
}
},
"glass.Expression": {
source: "constructor: (op, args) ->
@op = op
@args = args if args?
@
properties:
op:
type: 'string'
args:
type: 'array'
test: ->
return
peg = require 'pegjs'
fs = require 'fs'
parserSource = fs.readFileSync 'runtime/glass/Expression/_parser.pegjs', 'utf8'
parser = peg.buildParser parserSource
tests =
\"a.b.c\": {op:\"get\",args:[{op:\"get\",args:[{op:\"ref\",args:[\"a\"]},\"b\"]},\"c\"]}
\"a.1\": {op:\"get\",args:[{op:\"ref\",args:[\"a\"]},1]}
\"true\": true
\"false\": false
\"45.8\": 45.8
\"(45.8)\": 45.8
\"((45.8))\": 45.8
\"alpha\": {op:\"ref\",args:[\"alpha\"]}
\"35 + true * 2\": {op:\"+\", args:[35, {op:\"*\", args:[true,2]}]}
\" 5 * ( 2 + 2 ) \": {op:\"*\", args:[5, {op:\"+\", args:[2,2]}]}
\" ! ! true\": {op:\"!\",args:[{op:\"!\",args:[true]}]}
\"5 + -x\": {op:\"+\",args:[5,{op:\"-\",args:[{op:\"ref\",args:[\"x\"]}]}]}
\"true == 5 >= 2\": {op:\"==\",args:[true,{op:\">=\",args:[5,2]}]}
\"1 or 2 and 3\": {op:\"or\",args:[1,{op:\"and\",args:[2,3]}]}
\"1 ? 2 : 3\": {op:\"?:\",args:[1,2,3]}
\"1 ? 2 : 3 ? 4 : 5\" : {op:\"?:\",args:[1,2,{op:\"?:\",args:[3,4,5]}]}
\"a()(1,2)\" : {op:\"call\",args:[{op:\"call\",args:[{op:\"ref\",args:[\"a\"]},[]]},[1,2]]}
\"@\" : {op:\"this\"}
\"@foo\" : {op:\"get\",args:[{op:\"this\"},\"foo\"]}
'\"hello\"': \"hello\"
'\"\\\\t\\
\\
\\\\b\\\\\\\\foo\\\\\\/\"' : \"\\t
\\b\\\\foo\\/\"
\"[]\": {op:\"array\",args:[]}
\"[1,2]\": {op:\"array\",args:[1,2]}
\"[1+2]\": {op:\"array\",args:[{op:\"+\",args:[1,2]}]}
\"{}\": {op:\"object\",args:[]}
'{\"a\":2}': {op:\"object\",args:[[\"a\",2]]}
'{\"a\":2,\"b\":1+2}': {op:\"object\",args:[[\"a\",2],[\"b\",{op:\"+\",args:[1,2]}]]}
'@\"alpha\"': {op:\"get\",args:[{op:\"this\"},\"alpha\"]}
'*': {op:\"values\",args:[]}
'*.*': {op:\"values\",args:[{op:\"values\",args:[]}]}
\"foo.*\": {op:\"values\",args:[{op:\"ref\",args:[\"foo\"]}]}
\"..\": {op:\"ancestor\",args:[1]}
\"...\": {op:\"ancestor\",args:[2]}
\"@*{1+2}\": {op:\"eval\",args:[{op:\"values\",args:[{op:\"this\"}]},{op:\"+\",args:[1,2]}]}
\"/\": {op:\"root\"}
\"/foo\": {op:\"get\",args:[{op:\"root\"},\"foo\"]}
\"/*\": {op:\"values\",args:[{op:\"root\"}]}
for text, expected of tests
result = parser.parse text
if JSON.stringify(result) is JSON.stringify(expected)
console.log 'Pass: ' + text
else
console.log text, JSON.stringify result
return
",
input: "runtime\\glass\\Expression.coffee",
content: {
constructor: function(op, args) {
this.op = op;
if (args != null) {
this.args = args;
}
return this;
},
properties: {
op: {
type: "string",
name: "op",
writable: true
},
args: {
type: "array",
name: "args",
writable: true
}
},
test: function() {
var expected, fs, parser, parserSource, peg, result, tests, text;
return;
peg = require('pegjs');
fs = require('fs');
parserSource = fs.readFileSync('runtime/glass/Expression/_parser.pegjs', 'utf8');
parser = peg.buildParser(parserSource);
tests = {
"a.b.c": {
op: "get",
args: [{
op: "get",
args: [{
op: "ref",
args: ["a"]
},
"b"]
},
"c"]
},
"a.1": {
op: "get",
args: [{
op: "ref",
args: ["a"]
},
1]
},
"true": true,
"false": false,
"45.8": 45.8,
"(45.8)": 45.8,
"((45.8))": 45.8,
"alpha": {
op: "ref",
args: ["alpha"]
},
"35 + true * 2": {
op: "+",
args: [35, {
op: "*",
args: [true, 2]
}]
},
" 5 * ( 2 + 2 ) ": {
op: "*",
args: [5, {
op: "+",
args: [2, 2]
}]
},
" ! ! true": {
op: "!",
args: [{
op: "!",
args: [true]
}]
},
"5 + -x": {
op: "+",
args: [5, {
op: "-",
args: [{
op: "ref",
args: ["x"]
}]
}]
},
"true == 5 >= 2": {
op: "==",
args: [true, {
op: ">=",
args: [5, 2]
}]
},
"1 or 2 and 3": {
op: "or",
args: [1, {
op: "and",
args: [2, 3]
}]
},
"1 ? 2 : 3": {
op: "?:",
args: [1, 2, 3]
},
"1 ? 2 : 3 ? 4 : 5": {
op: "?:",
args: [1, 2, {
op: "?:",
args: [3, 4, 5]
}]
},
"a()(1,2)": {
op: "call",
args: [{
op: "call",
args: [{
op: "ref",
args: ["a"]
},
[]]
},
[1, 2]]
},
"@": {
op: "this"
},
"@foo": {
op: "get",
args: [{
op: "this"
},
"foo"]
},
'"hello"': "hello",
'"\\t
\\b\\\\foo\\\/"': "\t
\b\\foo\/",
"[]": {
op: "array",
args: []
},
"[1,2]": {
op: "array",
args: [1, 2]
},
"[1+2]": {
op: "array",
args: [{
op: "+",
args: [1, 2]
}]
},
"{}": {
op: "object",
args: []
},
'{"a":2}': {
op: "object",
args: [["a", 2]]
},
'{"a":2,"b":1+2}': {
op: "object",
args: [["a", 2], ["b", {
op: "+",
args: [1, 2]
}]]
},
'@"alpha"': {
op: "get",
args: [{
op: "this"
},
"alpha"]
},
'*': {
op: "values",
args: []
},
'*.*': {
op: "values",
args: [{
op: "values",
args: []
}]
},
"foo.*": {
op: "values",
args: [{
op: "ref",
args: ["foo"]
}]
},
"..": {
op: "ancestor",
args: [1]
},
"...": {
op: "ancestor",
args: [2]
},
"@*{1+2}": {
op: "eval",
args: [{
op: "values",
args: [{
op: "this"
}]
},
{
op: "+",
args: [1, 2]
}]
},
"/": {
op: "root"
},
"/foo": {
op: "get",
args: [{
op: "root"
},
"foo"]
},
"/*": {
op: "values",
args: [{
op: "root"
}]
}
};
for (text in tests) {
expected = tests[text];
result = parser.parse(text);
if (JSON.stringify(result) === JSON.stringify(expected)) {
console.log('Pass: ' + text);
} else {
console.log(text, JSON.stringify(result));
}
}
},
name: "Expression",
path: "glass.Expression",
namespace: "glass"
}
},
"glass.JSONMergePatch": {
source: "
# applies a patch to the target object and returns the resulting target
apply: (target, patch) ->
if target? and target isnt patch and isPlainObject(patch) and not isPrimitive(target)
for key, value of patch
if value is undefined
delete target[key]
else
target[key] = apply target[key], patch[key]
return target
else
return patch
# (path1, path2, path3.., patch) ->
create: ->
if arguments.length is 1
return arguments[0]
result = {}
current = result
for arg, i in arguments when i + 1 < arguments.length
last = i + 2 is arguments.length
current = current[arg] = if last then arguments[arguments.length-1] else {}
result
test: ->
assertEquals {a:{b:12}}, create 'a', 'b', 12
assertEquals {a:3}, apply({a:1,b:2}, {a:3,b:undefined})
",
input: "runtime\\glass\\JSONMergePatch.coffee",
content: {
apply: function(target, patch) {
var key, value;
if ((target != null) && target !== patch && isPlainObject(patch) && !isPrimitive(target)) {
for (key in patch) {
value = patch[key];
if (value === void 0) {
delete target[key];
} else {
target[key] = apply(target[key], patch[key]);
}
}
return target;
} else {
return patch;
}
},
create: function() {
var arg, current, i, last, result, _i, _len;
if (arguments.length === 1) {
return arguments[0];
}
result = {};
current = result;
for (i = _i = 0, _len = arguments.length; _i < _len; i = ++_i) {
arg = arguments[i];
if (! (i + 1 < arguments.length)) {
continue;
}
last = i + 2 === arguments.length;
current = current[arg] = last ? arguments[arguments.length - 1] : {};
}
return result;
},
test: function() {
assertEquals({
a: {
b: 12
}
},
create('a', 'b', 12));
return assertEquals({
a: 3
},
apply({
a: 1,
b: 2
},
{
a: 3,
b: void 0
}));
},
name: "JSONMergePatch",
path: "glass.JSONMergePatch",
namespace: "glass"
}
},
"glass.JSONPointer": {
source: "# json pointer implementation as per
# http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-05
_decodeStep: (step) -> step.replace(/~1/g, '/').replace(/~0/g, '~')
_getLastStep: (pointer) ->
_decodeStep pointer.substring(pointer.lastIndexOf('/') + 1)
_getParent: (pointer) ->
if not pointer?.length
null
else
pointer.substring(0, pointer.lastIndexOf('/'))
toArray: (pointer) ->
for step in pointer.substring(1).split('/')
_decodeStep step
get: (doc, pointer) ->
value = doc
if pointer.length
path = toArray pointer
for step in path when value?
value = value[step]
value
set: (doc, pointer, value) ->
parentPointer = _getParent pointer
if parentPointer?
parent = get doc, parentPointer
lastStep = _getLastStep pointer
parent[lastStep] = value
value
test: ->
assertEquals _getParent(\"/a/b/c\"), \"/a/b\"
assertEquals _getParent(\"/a\"), \"\"
assertEquals _getParent(\"\"), null
assertEquals _getLastStep(\"/a/b/c\"), \"c\"
assertEquals _getLastStep(\"/a~0~1\"), \"a~/\"
assertEquals _getLastStep(\"\"), \"\"
# tests as per spec
doc = {
\"foo\": [\"bar\", \"baz\"],
\"\": 0,
\"a/b\": 1,
\"c%d\": 2,
\"e^f\": 3,
\"g|h\": 4,
\"i\\\\j\": 5,
\"k\\\"l\": 6,
\" \": 7,
\"m~n\": 8
}
assertEquals get(doc, \"\"), doc
assertEquals get(doc, \"/foo\"), [\"bar\", \"baz\"]
assertEquals get(doc, \"/foo/0\"), \"bar\"
assertEquals get(doc, \"/\"), 0
assertEquals get(doc, \"/a~1b\"), 1
assertEquals get(doc, \"/c%d\"), 2
assertEquals get(doc, \"/e^f\"), 3
assertEquals get(doc, \"/g|h\"), 4
assertEquals get(doc, \"/i\\\\j\"), 5
assertEquals get(doc, \"/k\\\"l\"), 6
assertEquals get(doc, \"/ \"), 7
assertEquals get(doc, \"/m~0n\"), 8
# now test set
assertEquals set(doc, \"/\", 10), 10
assertEquals doc[\"\"], 10
assertEquals set(doc, \"/foo/0\", 10), 10
assertEquals doc.foo[0], 10",
input: "runtime\\glass\\JSONPointer.coffee",
content: {
toArray: function(pointer) {
var step, _i, _len, _ref, _results;
_ref = pointer.substring(1).split('/');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
step = _ref[_i];
_results.push(_decodeStep(step));
}
return _results;
},
get: function(doc, pointer) {
var path, step, value, _i, _len;
value = doc;
if (pointer.length) {
path = toArray(pointer);
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
}
return value;
},
set: function(doc, pointer, value) {
var lastStep, parent, parentPointer;
parentPointer = _getParent(pointer);
if (parentPointer != null) {
parent = get(doc, parentPointer);
lastStep = _getLastStep(pointer);
parent[lastStep] = value;
}
return value;
},
test: function() {
var doc;
assertEquals(_getParent("/a/b/c"), "/a/b");
assertEquals(_getParent("/a"), "");
assertEquals(_getParent(""), null);
assertEquals(_getLastStep("/a/b/c"), "c");
assertEquals(_getLastStep("/a~0~1"), "a~/");
assertEquals(_getLastStep(""), "");
doc = {
"foo": ["bar", "baz"],
"": 0,
"a/b": 1,
"c%d": 2,
"e^f": 3,
"g|h": 4,
"i\\j": 5,
"k\"l": 6,
" ": 7,
"m~n": 8
};
assertEquals(get(doc, ""), doc);
assertEquals(get(doc, "/foo"), ["bar", "baz"]);
assertEquals(get(doc, "/foo/0"), "bar");
assertEquals(get(doc, "/"), 0);
assertEquals(get(doc, "/a~1b"), 1);
assertEquals(get(doc, "/c%d"), 2);
assertEquals(get(doc, "/e^f"), 3);
assertEquals(get(doc, "/g|h"), 4);
assertEquals(get(doc, "/i\\j"), 5);
assertEquals(get(doc, "/k\"l"), 6);
assertEquals(get(doc, "/ "), 7);
assertEquals(get(doc, "/m~0n"), 8);
assertEquals(set(doc, "/", 10), 10);
assertEquals(doc[""], 10);
assertEquals(set(doc, "/foo/0", 10), 10);
return assertEquals(doc.foo[0], 10);
},
name: "JSONPointer",
path: "glass.JSONPointer",
namespace: "glass"
}
},
"glass.Observable": {
source: "properties:
is: (type) -> @constructor.implements[type.path ? type] is true
watchers:
serializable: false
watch: (property, watcher) ->
if isFunction property
watcher = property
property = ''
id = getId watcher
@patch 'watchers', property, id, watcher
# returns a function which will remove the watch
=> @patch 'watchers', property, getId(watcher), undefined
patch: (change) ->
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
try
JSONMergePatch.apply this, change
catch e
console.log e
finally
@notify change
return
notify: (change) ->
if @watchers?
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
for property, watchers of @watchers
if property.length is 0 or change.hasOwnProperty property
changeArg = if property.length is 0 then change else change[property]
for id, watcher of watchers
watcher this, changeArg
return
toJSON: ->
values =
class: @constructor.path
# serialize statically defined properties
for name, property of @constructor.properties
value = @[name]
if property.serializable isnt false and not isFunction(value)
values[name] = value
# serialize custom properties if allowed by schema
if @constructor.additionalProperties isnt false
for own name, value of @ when not isPrivate name
values[name] = value
values
toString: -> @toJSON()
test:
toJSON: ->
# I need this test later
# on a class that actually has serializable properties
a = new Observable
a.x = 12
a.y = ->
a.z = true
assertEquals a, {class:'glass.Observable', x:12,z:true}
watchAll: ->
# we should actually be able to watch ourselves get added to watchers
# this is very meta.
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch watcher
# now make sure we were called with our own watcher
assert watchArgs[0] is a
assert watchArgs[1]?.watchers?[\"\"]?
# reset watchArgs, and watch something else
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assertEquals a.a, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {a:{b:3}}
# now unwatch
unwatch()
# make sure universal watcher is now empty
assertEquals a.watchers[\"\"], {}
# now reset and do a new event, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
watchProperty: ->
# watch a property
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch \"foo\", watcher
# now make sure we were not called
assert watchArgs.length is 0
# reset watchArgs, and watch something else
a.patch \"foo\", \"b\", 3
assertEquals a.foo, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {b:3}
# now reset and do a different property, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
# now unwatch
unwatch()
# make sure we no longer see foo
watchArgs.length = 0
a.patch \"foo\", \"b\", 4
assert watchArgs.length is 0
",
input: "runtime\\glass\\Observable.coffee",
content: {
properties: {
is: {
value: function(type) {
var _ref;
return this.constructor["implements"][(_ref = type.path) != null ? _ref: type] === true;
},
name: "is"
},
watchers: {
serializable: false,
name: "watchers",
writable: true
},
watch: {
value: function(property, watcher) {
var id, _this = this;
if (isFunction(property)) {
watcher = property;
property = '';
}
id = getId(watcher);
this.patch('watchers', property, id, watcher);
return function() {
return _this.patch('watchers', property, getId(watcher), void 0);
};
},
name: "watch"
},
patch: {
value: function(change) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
try {
JSONMergePatch.apply(this, change);
} catch(e) {
console.log(e);
} finally {
this.notify(change);
}
},
name: "patch"
},
notify: {
value: function(change) {
var changeArg, id, property, watcher, watchers, _ref;
if (this.watchers != null) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
_ref = this.watchers;
for (property in _ref) {
watchers = _ref[property];
if (property.length === 0 || change.hasOwnProperty(property)) {
changeArg = property.length === 0 ? change: change[property];
for (id in watchers) {
watcher = watchers[id];
watcher(this, changeArg);
}
}
}
}
},
name: "notify"
},
toJSON: {
value: function() {
var name, property, value, values, _ref;
values = {
"class": this.constructor.path
};
_ref = this.constructor.properties;
for (name in _ref) {
property = _ref[name];
value = this[name];
if (property.serializable !== false && !isFunction(value)) {
values[name] = value;
}
}
if (this.constructor.additionalProperties !== false) {
for (name in this) {
if (!__hasProp.call(this, name)) continue;
value = this[name];
if (!isPrivate(name)) {
values[name] = value;
}
}
}
return values;
},
name: "toJSON"
},
toString: {
value: function() {
return this.toJSON();
},
name: "toString"
}
},
test: {
toJSON: function() {
var a;
a = new Observable;
a.x = 12;
a.y = function() {};
a.z = true;
return assertEquals(a, {
"class": 'glass.Observable',
x: 12,
z: true
});
},
watchAll: function() {
var a, unwatch, watchArgs, watcher, _ref, _ref1;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch(watcher);
assert(watchArgs[0] === a);
assert(((_ref = watchArgs[1]) != null ? (_ref1 = _ref.watchers) != null ? _ref1[""] : void 0 : void 0) != null);
watchArgs.length = 0;
a.patch("a", "b", 3);
assertEquals(a.a, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
a: {
b: 3
}
});
unwatch();
assertEquals(a.watchers[""], {});
watchArgs.length = 0;
a.patch("a", "b", 3);
return assert(watchArgs.length === 0);
},
watchProperty: function() {
var a, unwatch, watchArgs, watcher;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch("foo", watcher);
assert(watchArgs.length === 0);
a.patch("foo", "b", 3);
assertEquals(a.foo, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
b: 3
});
watchArgs.length = 0;
a.patch("a", "b", 3);
assert(watchArgs.length === 0);
unwatch();
watchArgs.length = 0;
a.patch("foo", "b", 4);
return assert(watchArgs.length === 0);
}
},
name: "Observable",
path: "glass.Observable",
namespace: "glass"
}
},
glass: {
source: "require:
\tString: true
# runtime type tests
isFunction: (object) -> object? and typeof object is 'function'
isString: (object) -> object?.constructor is String
isArray: (object) -> Array.isArray object
isBoolean: (object) -> object? and typeof object is 'boolean'
isNumber: (object) -> object? and typeof object is 'number'
isObject: (object) -> typeof object is 'object'
isPlainObject: (object) -> object?.constructor is Object
isPrototype: (object) -> object? and object is object.constructor.prototype
isDate: (object) -> object?.constructor is Date
isPrimitive: (object) -> isString(object) or isBoolean(object) or isNumber(object) or isDate(object)
isPrivate: (property) -> property?[0] is '_'
# generic utility functions
values: (object) -> (value for key, value of object)
# generic patch method, uses patch method built into object if present
patch: (target, pathAndPatch...) ->
patch = JSONMergePatch.create.apply null, pathAndPatch
if isFunction target?.patch
target.patch patch
else
glass.JSONMergePatch.apply target, patch
# testing assertions
_getStackLocationInfo: (e, depth) ->
line = e.stack?.split('
')[depth]
return null unless line?
match = /\\(([\\w\\W]*?):(\\d+):(\\d+)\\)/.exec line
return {
file: match[1]
line: parseInt match[2]
column: parseInt match[3]
}
_throwAssertionFailure: (message) ->
try
throw new Error \"Assertion failed: \" + message
catch e
info = _getStackLocationInfo e, 3
if info?
_dumpFile info.file, info.line - 2, info.line + 2, info.line
throw e
_dumpFile: (file, from=1, to, highlight) ->
fs = require 'fs'
return unless fs?
try
content = fs.readFileSync(file).toString()
catch e
content = \"Source not found: #{e}\"
console.log '------------------------------------------------'
console.log file
console.log '------------------------------------------------'
number = 1
if content?
lines = content.split /
|
/
to ?= lines.length
for line in lines
lineNumber = number++
if lineNumber >= from and lineNumber <= to
num = String lineNumber
while num.length < 3
num += ' '
if lineNumber is highlight
`console.log(\"\\033[91m\" + num + \": \" + line + \"\\033[0m\");`
else
`console.log(num + \": \" + line);`
console.log '------------------------------------------------'
assert: (a) ->
_throwAssertionFailure JSON.stringify(a) unless a
assertTrue: (a) ->
_throwAssertionFailure JSON.stringify(a) + \" != true\" unless a is true
assertEquals: (a, b) ->
if JSON.stringify(a) isnt JSON.stringify(b)
_throwAssertionFailure JSON.stringify(a) + ' != ' + JSON.stringify(b)
# gets a unique string identifier for any object
getId:
do: ->
counter = 0
(a) ->
if a is null
return '__null__'
if a is undefined
return '__undefined__'
if typeof a is 'object' or typeof a is 'function'
return a.id ?= '__' + (counter++) + '__'
# 12 == \"12\" under this technique
return a.toString()
getType: (path) ->
array = if isArray path then path else path.split '.'
value = global
for step in path when value?
value = value[step]
throw new Error \"Type not found: #{path}\" unless isFunction value
value
test:
values: ->
assertEquals values({a:1,b:3,c:2}), [1,3,2]
patch: ->
x = {a:{foo:1,bar:3},b:2}
patch x, 'a', 'foo', 5
assertEquals x.a.foo, 5
",
input: "runtime\\glass.coffee",
content: {
require: {
String: true
},
isFunction: function(object) {
return (object != null) && typeof object === 'function';
},
isString: function(object) {
return (object != null ? object.constructor: void 0) === String;
},
isArray: function(object) {
return Array.isArray(object);
},
isBoolean: function(object) {
return (object != null) && typeof object === 'boolean';
},
isNumber: function(object) {
return (object != null) && typeof object === 'number';
},
isObject: function(object) {
return typeof object === 'object';
},
isPlainObject: function(object) {
return (object != null ? object.constructor: void 0) === Object;
},
isPrototype: function(object) {
return (object != null) && object === object.constructor.prototype;
},
isDate: function(object) {
return (object != null ? object.constructor: void 0) === Date;
},
isPrimitive: function(object) {
return isString(object) || isBoolean(object) || isNumber(object) || isDate(object);
},
isPrivate: function(property) {
return (property != null ? property[0] : void 0) === '_';
},
values: function(object) {
var key, value, _results;
_results = [];
for (key in object) {
value = object[key];
_results.push(value);
}
return _results;
},
patch: function() {
var patch, pathAndPatch, target;
target = arguments[0],
pathAndPatch = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
patch = JSONMergePatch.create.apply(null, pathAndPatch);
if (isFunction(target != null ? target.patch: void 0)) {
return target.patch(patch);
} else {
return glass.JSONMergePatch.apply(target, patch);
}
},
assert: function(a) {
if (!a) {
return _throwAssertionFailure(JSON.stringify(a));
}
},
assertTrue: function(a) {
if (a !== true) {
return _throwAssertionFailure(JSON.stringify(a) + " != true");
}
},
assertEquals: function(a, b) {
if (JSON.stringify(a) !== JSON.stringify(b)) {
return _throwAssertionFailure(JSON.stringify(a) + ' != ' + JSON.stringify(b));
}
},
getId: {
do: function() {
var counter;
counter = 0;
return function(a) {
var _ref;
if (a === null) {
return '__null__';
}
if (a === void 0) {
return '__undefined__';
}
if (typeof a === 'object' || typeof a === 'function') {
return (_ref = a.id) != null ? _ref: a.id = '__' + (counter++) + '__';
}
return a.toString();
};
}
},
getType: function(path) {
var array, step, value, _i, _len;
array = isArray(path) ? path: path.split('.');
value = global;
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
if (!isFunction(value)) {
throw new Error("Type not found: " + path);
}
return value;
},
test: {
values: function() {
return assertEquals(values({
a: 1,
b: 3,
c: 2
}), [1, 3, 2]);
},
patch: function() {
var x;
x = {
a: {
foo: 1,
bar: 3
},
b: 2
};
patch(x, 'a', 'foo', 5);
return assertEquals(x.a.foo, 5);
}
},
name: "glass",
path: "glass",
namespace: ""
}
},
String: {
source: "extension: true
properties:
\tstartsWith: (s) -> @slice(0,s.length) is s
\tendsWith: (s) -> @slice(-s.length) is s
\tcontains: (s) -> @indexOf(s) >= 0
\ttoArray: () -> @split ''",
input: "runtime\\String.coffee",
content: {
extension: true,
properties: {
startsWith: {
value: function(s) {
return this.slice(0, s.length) === s;
},
name: "startsWith"
},
endsWith: {
value: function(s) {
return this.slice( - s.length) === s;
},
name: "endsWith"
},
contains: {
value: function(s) {
return this.indexOf(s) >= 0;
},
name: "contains"
},
toArray: {
value: function() {
return this.split('');
},
name: "toArray"
}
},
name: "String",
path: "String",
namespace: ""
}
}
}
} | {
options: {
input: {
dir: "runtime",
match: /\.(coffee|pegjs)$/
},
output: {
dir: "www/js"
},
script: {
includes: "www/includes.html",
prefix: "/js/"
},
module: {
main: "glass.js",
prefix: "./www/js/"
},
debug: "buildlog.html",
test: "glass.allTests",
addon: {
pregenerate: {
addUri: function(schema) {
var content, type, typeName, _ref2, _ref3;
_ref2 = schema.types;
for (typeName in _ref2) {
type = _ref2[typeName];
content = type.content;
if (content.extension) {
continue;
}
if ((_ref3 = content.uri) == null) {
content.uri = "global:/" + (content.path.replace(/\./g, '/'));
}
}
return schema;
}
}
},
namespace: ""
},
types: {
"glass.Component": {
source: "extends: 'Observable'
constructor: (properties) ->
@patch properties
# now site ourselves on our parent
if @parent
id = getId @
patch @parent, id, @
@
properties:
id:
description: 'string which uniquely identifies this component within its parent'
type: 'string'
parent:
description: 'the object that contains this component'
serializable: false
type: 'object'
disposed: false
dispose: -> @patch 'disposed', true
notify: (change) ->
Observable.prototype.notify.apply this, arguments
if change?.disposed
# dispose of any disposable children
for id, child of @ when child?.parent is @
child.dispose?()
# remove self from parent
if @id and @parent
patch @parent, @id, undefined
return
test:
lifecycle: ->
parent = new Component
assert not parent.id?
assert not parent.parent?
child = new Component parent:parent
# id should be automatically assigned
assert isString child.id
assert parent is child.parent
assert parent[child.id] is child
assert parent.hasOwnProperty child.id
parent.dispose()
assert child.disposed is true
assert not parent.hasOwnProperty child.id
nonEnumerability: ->
visibleKeys = (key for key of new Component)
assertEquals visibleKeys, []",
input: "runtime\\glass\\Component.coffee",
content: {
extends: ["glass.Observable"],
constructor: function(properties) {
var id;
this.patch(properties);
if (this.parent) {
id = getId(this);
patch(this.parent, id, this);
}
return this;
},
properties: {
id: {
description: "string which uniquely identifies this component within its parent",
type: "string",
name: "id",
writable: true
},
parent: {
description: "the object that contains this component",
serializable: false,
type: "object",
name: "parent",
writable: true
},
disposed: {
value: false,
name: "disposed",
writable: true
},
dispose: {
value: function() {
return this.patch('disposed', true);
},
name: "dispose"
},
notify: {
value: function(change) {
var child, id;
Observable.prototype.notify.apply(this, arguments);
if (change != null ? change.disposed: void 0) {
for (id in this) {
child = this[id];
if ((child != null ? child.parent: void 0) === this) {
if (typeof child.dispose === "function") {
child.dispose();
}
}
}
if (this.id && this.parent) {
patch(this.parent, this.id, void 0);
}
}
},
name: "notify"
}
},
test: {
lifecycle: function() {
var child, parent;
parent = new Component;
assert(!(parent.id != null));
assert(!(parent.parent != null));
child = new Component({
parent: parent
});
assert(isString(child.id));
assert(parent === child.parent);
assert(parent[child.id] === child);
assert(parent.hasOwnProperty(child.id));
parent.dispose();
assert(child.disposed === true);
return assert(!parent.hasOwnProperty(child.id));
},
nonEnumerability: function() {
var key, visibleKeys;
visibleKeys = (function() {
var _results;
_results = [];
for (key in new Component) {
_results.push(key);
}
return _results;
})();
return assertEquals(visibleKeys, []);
}
},
name: "Component",
path: "glass.Component",
namespace: "glass",
require: {
glass: "glass",
"glass.Observable": "Observable"
},
import: {
"glass.Observable": "Observable",
"glass.isString": "isString",
"glass.patch": "patch",
"glass.assert": "assert",
"glass.assertEquals": "assertEquals",
"glass.getId": "getId"
}
}
},
"glass.Container": {
source: "extends: 'Observable'
properties:
watch: ->
unwatch: ->
",
input: "runtime\\glass\\Container.coffee",
content: {
extends: ["glass.Observable"],
properties: {
watch: {
value: function() {},
name: "watch"
},
unwatch: {
value: function() {},
name: "unwatch"
}
},
name: "Container",
path: "glass.Container",
namespace: "glass",
require: {
glass: "glass",
"glass.Observable": "Observable"
},
import: {}
}
},
"glass.Expression._parser": {
source: "{
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e,array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++)
array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
}
start = expression
expression = conditional
conditional = e:or args:(\"?\" b:expression \":\" c:expression {return [b,c];})* {
while (args.length > 0) {
e = expr(\"?:\", [e].concat(args.pop()));
}
return e;
}
or = a:and b:((\"or\") and)* { return joinLeft(a,b); }
and = a:equality b:((\"and\") equality)* { return joinLeft(a,b); }
equality = a:rel b:((\"==\" / \"!=\") rel)* { return joinLeft(a,b); }
rel = a:sum b:((\"<=\" / \">=\" / \"<\" / \">\") sum)* { return joinLeft(a,b); }
sum = a:product b:((\"+\" / \"-\") product)* { return joinLeft(a,b); }
product = a:not b:((\"*\" / \"div\" / \"mod\") not)* { return joinLeft(a,b); }
not = ops:(s op:(\"!\" / \"~\" / \"+\" / \"-\") { return op; })* b:primary { return unaryRight(ops,b); }
primary = s a:(group / literal / path) s { return a; }
group = \"(\" a:expression \")\" { return a; }
literal = s a:(boolean / number / string / array / object) s { return a; }
boolean = a:(\"true\" / \"false\") { return a == \"true\"; }
number = a:([0-9]+ (\".\" [0-9]+)?) { return parseFloat(toString(a)); }
hex = [a-fA-F0-9]
// as per JSON http://www.json.org
string = a:( '\"' (
[\\u0000-\\u0021\\u0023-\\u005c\\u005e-\\uffff] // all unicode chars except \\ and \"
/ (\"\\\\\" (\"\\\"\" / \"\\\\\" / \"\\/\" / \"b\" / \"f\" / \"n\" / \"r\" / \"t\" / (\"u\" hex hex hex hex)))
)* '\"' )
{ return JSON.parse(toString(a)); }
array = \"[\" a:values \"]\" { return expr(\"array\", a); }
values = first:expression? args:(\",\" b:expression {return b;})* {
if (first != \"\") { args.unshift(first); } return args;
}
object = \"{\" a:keyvalues \"}\" { return expr(\"object\", a); }
keyvalue = s a:string s \":\" b:expression { return [a,b]; }
keyvalues = first:keyvalue? rest:(\",\" b:keyvalue {return b;})* {
if (first) { rest.unshift(first); } return rest;
}
ref = a:(\"//\" / \"/\" / \"$\" / \"**\" / \"*\" / \"..\" / \".\") b:slashProperty? {
e = expr(a); if (b) { b.args.unshift(e); e = b; } return e;
}
/ a:id { return expr(\"ref\", [a]); }
id = a:[a-z_]+ b:[a-z_0-9]* { return a.join('') + b.join(''); }
property = \"/\" a:slashProperty { return a; }
/ \"{\" a:expression \"}\" { return expr(\"{}\", [a]); } // locally scoped expression
/ \"[\" a:expression \"]\" { return expr(\"[]\", [a]); } // predicate
slashProperty = a:(id/number/string) { return expr(\"/\", [a]); }
/ a:(\"..\" / \"*\") { return expr(a, []); }
s \"space\" = [ ]* { return ''; }
path = a:root b:step* {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
}
root = a:implicitDotRoot b:dotStep? { return joinPath(a,b); }
/ explicitDotRoot
step = \".\" a:dotStep { return a; }
/ noDotStep
implicitDotRoot = \"/\" { return expr(\"root\"); }
/ \"@\" { return expr(\"this\"); }
/ \".\" a:\".\"+ { return expr(\"ancestor\", [a.length]); }
explicitDotRoot = a:id { return expr(\"ref\", [a]); }
/ \"*\" { return expr(\"values\", []); }
dotStep = a:(id / string / number) { return expr(\"get\", [a]); }
/ \"*\" { return expr(\"values\", []); }
noDotStep = \"{\" a:expression \"}\" { return expr(\"eval\", [a]); }
/ \"[\" a:expression \"]\" { return expr(\"pred\", [a]); }
/ \"(\" a:values \")\" { return expr(\"call\", [a]); }
",
input: "runtime\\glass\\Expression\\_parser.pegjs",
content: {
value: {
parse: function(input, startRule) {
var parseFunctions = {
"conditional": parse_conditional,
"or": parse_or,
"and": parse_and,
"equality": parse_equality,
"rel": parse_rel,
"sum": parse_sum,
"product": parse_product,
"not": parse_not,
"primary": parse_primary,
"group": parse_group,
"literal": parse_literal,
"boolean": parse_boolean,
"number": parse_number,
"hex": parse_hex,
"string": parse_string,
"array": parse_array,
"values": parse_values,
"object": parse_object,
"keyvalue": parse_keyvalue,
"keyvalues": parse_keyvalues,
"ref": parse_ref,
"id": parse_id,
"property": parse_property,
"slashProperty": parse_slashProperty,
"s": parse_s,
"path": parse_path,
"root": parse_root,
"step": parse_step,
"implicitDotRoot": parse_implicitDotRoot,
"explicitDotRoot": parse_explicitDotRoot,
"dotStep": parse_dotStep,
"noDotStep": parse_noDotStep
};
if (startRule !== undefined) {
if (parseFunctions[startRule] === undefined) {
throw new Error("Invalid rule name: " + quote(startRule) + ".");
}
} else {
startRule = "conditional";
}
var pos = 0;
var reportFailures = 0;
var rightmostFailuresPos = 0;
var rightmostFailuresExpected = [];
function padLeft(input, padding, length) {
var result = input;
var padLength = length - input.length;
for (var i = 0; i < padLength; i++) {
result = padding + result;
}
return result;
}
function escape(ch) {
var charCode = ch.charCodeAt(0);
var escapeChar;
var length;
if (charCode <= 0xFF) {
escapeChar = 'x';
length = 2;
} else {
escapeChar = 'u';
length = 4;
}
return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
}
function matchFailed(failure) {
if (pos < rightmostFailuresPos) {
return;
}
if (pos > rightmostFailuresPos) {
rightmostFailuresPos = pos;
rightmostFailuresExpected = [];
}
rightmostFailuresExpected.push(failure);
}
function parse_conditional() {
var result0, result1, result2, result3, result4, result5;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_or();
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, e, args) {
while (args.length > 0) {
e = expr("?:", [e].concat(args.pop()));
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_or() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_and();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_and() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_equality();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_equality() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_rel();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_rel() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_sum();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_sum() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_product();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_product() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_not();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_not() {
var result0, result1, result2;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = [];
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
while (result1 !== null) {
result0.push(result1);
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
}
if (result0 !== null) {
result1 = parse_primary();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, ops, b) {
return unaryRight(ops, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_primary() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_group();
if (result1 === null) {
result1 = parse_literal();
if (result1 === null) {
result1 = parse_path();
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_group() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_literal() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_boolean();
if (result1 === null) {
result1 = parse_number();
if (result1 === null) {
result1 = parse_string();
if (result1 === null) {
result1 = parse_array();
if (result1 === null) {
result1 = parse_object();
}
}
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_boolean() {
var result0;
var pos0;
pos0 = pos;
if (input.substr(pos, 4) === "true") {
result0 = "true";
pos += 4;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"true\"");
}
}
if (result0 === null) {
if (input.substr(pos, 5) === "false") {
result0 = "false";
pos += 5;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"false\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a == "true";
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_number() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
pos2 = pos;
if (input.charCodeAt(pos) === 46) {
result1 = ".";
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result1 !== null) {
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result3 !== null) {
result2 = [];
while (result3 !== null) {
result2.push(result3);
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result2 = null;
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos2;
}
} else {
result1 = null;
pos = pos2;
}
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return parseFloat(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_hex() {
var result0;
if (/^[a-fA-F0-9]/.test(input.charAt(pos))) {
result0 = input.charAt(pos);
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("[a-fA-F0-9]");
}
}
return result0;
}
function parse_string() {
var result0, result1, result2, result3, result4, result5, result6, result7;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 34) {
result0 = "\"";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result0 !== null) {
result1 = [];
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
}
if (result1 !== null) {
if (input.charCodeAt(pos) === 34) {
result2 = "\"";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return JSON.parse(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_array() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("array", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_values() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_conditional();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, args) {
if (first != "") {
args.unshift(first);
}
return args;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_object() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_keyvalues();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("object", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalue() {
var result0, result1, result2, result3, result4;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_string();
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
if (input.charCodeAt(pos) === 58) {
result3 = ":";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result3 !== null) {
result4 = parse_conditional();
if (result4 !== null) {
result0 = [result0, result1, result2, result3, result4];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return [a, b];
})(pos0, result0[1], result0[4]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalues() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_keyvalue();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, rest) {
if (first) {
rest.unshift(first);
}
return rest;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_ref() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.substr(pos, 2) === "//") {
result0 = "//";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"//\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 36) {
result0 = "$";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"$\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "**") {
result0 = "**";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"**\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
}
}
}
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
e = expr(a);
if (b) {
b.args.unshift(e);
e = b;
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_id() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
result1 = [];
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return a.join('') + b.join('');
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_property() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("{}", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("[]", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_slashProperty() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_number();
if (result0 === null) {
result0 = parse_string();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("/", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(a, []);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_s() {
var result0, result1;
var pos0;
reportFailures++;
pos0 = pos;
result0 = [];
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
while (result1 !== null) {
result0.push(result1);
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
}
if (result0 !== null) {
result0 = (function(offset) {
return '';
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
reportFailures--;
if (reportFailures === 0 && result0 === null) {
matchFailed("space");
}
return result0;
}
function parse_path() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_root();
if (result0 !== null) {
result1 = [];
result2 = parse_step();
while (result2 !== null) {
result1.push(result2);
result2 = parse_step();
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_root() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_implicitDotRoot();
if (result0 !== null) {
result1 = parse_dotStep();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinPath(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_explicitDotRoot();
}
return result0;
}
function parse_step() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
result1 = parse_dotStep();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_noDotStep();
}
return result0;
}
function parse_implicitDotRoot() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("root");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 64) {
result0 = "@";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"@\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("this");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result2 !== null) {
result1 = [];
while (result2 !== null) {
result1.push(result2);
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
} else {
result1 = null;
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ancestor", [a.length]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_explicitDotRoot() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_dotStep() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_string();
if (result0 === null) {
result0 = parse_number();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("get", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_noDotStep() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("eval", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("pred", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("call", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function cleanupExpected(expected) {
expected.sort();
var lastExpected = null;
var cleanExpected = [];
for (var i = 0; i < expected.length; i++) {
if (expected[i] !== lastExpected) {
cleanExpected.push(expected[i]);
lastExpected = expected[i];
}
}
return cleanExpected;
}
function computeErrorPosition() {
/*
* The first idea was to use |String.split| to break the input up to the
* error position along newlines and derive the line and column from
* there. However IE's |split| implementation is so broken that it was
* enough to prevent it.
*/
var line = 1;
var column = 1;
var seenCR = false;
for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
var ch = input.charAt(i);
if (ch === "
") {
if (!seenCR) {
line++;
}
column = 1;
seenCR = false;
} else if (ch === "
" || ch === "\u2028" || ch === "\u2029") {
line++;
column = 1;
seenCR = true;
} else {
column++;
seenCR = false;
}
}
return {
line: line,
column: column
};
}
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e, array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++) array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
var result = parseFunctions[startRule]();
/*
* The parser is now in one of the following three states:
*
* 1. The parser successfully parsed the whole input.
*
* - |result !== null|
* - |pos === input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 2. The parser successfully parsed only a part of the input.
*
* - |result !== null|
* - |pos < input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 3. The parser did not successfully parse any part of the input.
*
* - |result === null|
* - |pos === 0|
* - |rightmostFailuresExpected| contains at least one failure
*
* All code following this comment (including called functions) must
* handle these states.
*/
if (result === null || pos !== input.length) {
var offset = Math.max(pos, rightmostFailuresPos);
var found = offset < input.length ? input.charAt(offset) : null;
var errorPosition = computeErrorPosition();
throw new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column);
}
return result;
},
toSource: function() {
return this._source;
},
SyntaxError: function(expected, found, offset, line, column) {
function buildMessage(expected, found) {
var expectedHumanized, foundHumanized;
switch (expected.length) {
case 0:
expectedHumanized = "end of input";
break;
case 1:
expectedHumanized = expected[0];
break;
default:
expectedHumanized = expected.slice(0, expected.length - 1).join(", ") + " or " + expected[expected.length - 1];
}
foundHumanized = found ? quote(found) : "end of input";
return "Expected " + expectedHumanized + " but " + foundHumanized + " found.";
}
this.name = "SyntaxError";
this.expected = expected;
this.found = found;
this.message = buildMessage(expected, found);
this.offset = offset;
this.line = line;
this.column = column;
}
},
name: "_parser",
path: "glass.Expression._parser",
namespace: "glass.Expression",
require: {
"glass.Expression": "Expression"
},
import: {
"glass.values": "values"
}
}
},
"glass.Expression": {
source: "constructor: (op, args) ->
@op = op
@args = args if args?
@
properties:
op:
type: 'string'
args:
type: 'array'
test: ->
return
peg = require 'pegjs'
fs = require 'fs'
parserSource = fs.readFileSync 'runtime/glass/Expression/_parser.pegjs', 'utf8'
parser = peg.buildParser parserSource
tests =
\"a.b.c\": {op:\"get\",args:[{op:\"get\",args:[{op:\"ref\",args:[\"a\"]},\"b\"]},\"c\"]}
\"a.1\": {op:\"get\",args:[{op:\"ref\",args:[\"a\"]},1]}
\"true\": true
\"false\": false
\"45.8\": 45.8
\"(45.8)\": 45.8
\"((45.8))\": 45.8
\"alpha\": {op:\"ref\",args:[\"alpha\"]}
\"35 + true * 2\": {op:\"+\", args:[35, {op:\"*\", args:[true,2]}]}
\" 5 * ( 2 + 2 ) \": {op:\"*\", args:[5, {op:\"+\", args:[2,2]}]}
\" ! ! true\": {op:\"!\",args:[{op:\"!\",args:[true]}]}
\"5 + -x\": {op:\"+\",args:[5,{op:\"-\",args:[{op:\"ref\",args:[\"x\"]}]}]}
\"true == 5 >= 2\": {op:\"==\",args:[true,{op:\">=\",args:[5,2]}]}
\"1 or 2 and 3\": {op:\"or\",args:[1,{op:\"and\",args:[2,3]}]}
\"1 ? 2 : 3\": {op:\"?:\",args:[1,2,3]}
\"1 ? 2 : 3 ? 4 : 5\" : {op:\"?:\",args:[1,2,{op:\"?:\",args:[3,4,5]}]}
\"a()(1,2)\" : {op:\"call\",args:[{op:\"call\",args:[{op:\"ref\",args:[\"a\"]},[]]},[1,2]]}
\"@\" : {op:\"this\"}
\"@foo\" : {op:\"get\",args:[{op:\"this\"},\"foo\"]}
'\"hello\"': \"hello\"
'\"\\\\t\\
\\
\\\\b\\\\\\\\foo\\\\\\/\"' : \"\\t
\\b\\\\foo\\/\"
\"[]\": {op:\"array\",args:[]}
\"[1,2]\": {op:\"array\",args:[1,2]}
\"[1+2]\": {op:\"array\",args:[{op:\"+\",args:[1,2]}]}
\"{}\": {op:\"object\",args:[]}
'{\"a\":2}': {op:\"object\",args:[[\"a\",2]]}
'{\"a\":2,\"b\":1+2}': {op:\"object\",args:[[\"a\",2],[\"b\",{op:\"+\",args:[1,2]}]]}
'@\"alpha\"': {op:\"get\",args:[{op:\"this\"},\"alpha\"]}
'*': {op:\"values\",args:[]}
'*.*': {op:\"values\",args:[{op:\"values\",args:[]}]}
\"foo.*\": {op:\"values\",args:[{op:\"ref\",args:[\"foo\"]}]}
\"..\": {op:\"ancestor\",args:[1]}
\"...\": {op:\"ancestor\",args:[2]}
\"@*{1+2}\": {op:\"eval\",args:[{op:\"values\",args:[{op:\"this\"}]},{op:\"+\",args:[1,2]}]}
\"/\": {op:\"root\"}
\"/foo\": {op:\"get\",args:[{op:\"root\"},\"foo\"]}
\"/*\": {op:\"values\",args:[{op:\"root\"}]}
for text, expected of tests
result = parser.parse text
if JSON.stringify(result) is JSON.stringify(expected)
console.log 'Pass: ' + text
else
console.log text, JSON.stringify result
return
",
input: "runtime\\glass\\Expression.coffee",
content: {
constructor: function(op, args) {
this.op = op;
if (args != null) {
this.args = args;
}
return this;
},
properties: {
op: {
type: "string",
name: "op",
writable: true
},
args: {
type: "array",
name: "args",
writable: true
}
},
test: function() {
var expected, fs, parser, parserSource, peg, result, tests, text;
return;
peg = require('pegjs');
fs = require('fs');
parserSource = fs.readFileSync('runtime/glass/Expression/_parser.pegjs', 'utf8');
parser = peg.buildParser(parserSource);
tests = {
"a.b.c": {
op: "get",
args: [{
op: "get",
args: [{
op: "ref",
args: ["a"]
},
"b"]
},
"c"]
},
"a.1": {
op: "get",
args: [{
op: "ref",
args: ["a"]
},
1]
},
"true": true,
"false": false,
"45.8": 45.8,
"(45.8)": 45.8,
"((45.8))": 45.8,
"alpha": {
op: "ref",
args: ["alpha"]
},
"35 + true * 2": {
op: "+",
args: [35, {
op: "*",
args: [true, 2]
}]
},
" 5 * ( 2 + 2 ) ": {
op: "*",
args: [5, {
op: "+",
args: [2, 2]
}]
},
" ! ! true": {
op: "!",
args: [{
op: "!",
args: [true]
}]
},
"5 + -x": {
op: "+",
args: [5, {
op: "-",
args: [{
op: "ref",
args: ["x"]
}]
}]
},
"true == 5 >= 2": {
op: "==",
args: [true, {
op: ">=",
args: [5, 2]
}]
},
"1 or 2 and 3": {
op: "or",
args: [1, {
op: "and",
args: [2, 3]
}]
},
"1 ? 2 : 3": {
op: "?:",
args: [1, 2, 3]
},
"1 ? 2 : 3 ? 4 : 5": {
op: "?:",
args: [1, 2, {
op: "?:",
args: [3, 4, 5]
}]
},
"a()(1,2)": {
op: "call",
args: [{
op: "call",
args: [{
op: "ref",
args: ["a"]
},
[]]
},
[1, 2]]
},
"@": {
op: "this"
},
"@foo": {
op: "get",
args: [{
op: "this"
},
"foo"]
},
'"hello"': "hello",
'"\\t
\\b\\\\foo\\\/"': "\t
\b\\foo\/",
"[]": {
op: "array",
args: []
},
"[1,2]": {
op: "array",
args: [1, 2]
},
"[1+2]": {
op: "array",
args: [{
op: "+",
args: [1, 2]
}]
},
"{}": {
op: "object",
args: []
},
'{"a":2}': {
op: "object",
args: [["a", 2]]
},
'{"a":2,"b":1+2}': {
op: "object",
args: [["a", 2], ["b", {
op: "+",
args: [1, 2]
}]]
},
'@"alpha"': {
op: "get",
args: [{
op: "this"
},
"alpha"]
},
'*': {
op: "values",
args: []
},
'*.*': {
op: "values",
args: [{
op: "values",
args: []
}]
},
"foo.*": {
op: "values",
args: [{
op: "ref",
args: ["foo"]
}]
},
"..": {
op: "ancestor",
args: [1]
},
"...": {
op: "ancestor",
args: [2]
},
"@*{1+2}": {
op: "eval",
args: [{
op: "values",
args: [{
op: "this"
}]
},
{
op: "+",
args: [1, 2]
}]
},
"/": {
op: "root"
},
"/foo": {
op: "get",
args: [{
op: "root"
},
"foo"]
},
"/*": {
op: "values",
args: [{
op: "root"
}]
}
};
for (text in tests) {
expected = tests[text];
result = parser.parse(text);
if (JSON.stringify(result) === JSON.stringify(expected)) {
console.log('Pass: ' + text);
} else {
console.log(text, JSON.stringify(result));
}
}
},
name: "Expression",
path: "glass.Expression",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.Expression._parser": "_parser",
"glass.values": "values"
}
}
},
"glass.JSONMergePatch": {
source: "
# applies a patch to the target object and returns the resulting target
apply: (target, patch) ->
if target? and target isnt patch and isPlainObject(patch) and not isPrimitive(target)
for key, value of patch
if value is undefined
delete target[key]
else
target[key] = apply target[key], patch[key]
return target
else
return patch
# (path1, path2, path3.., patch) ->
create: ->
if arguments.length is 1
return arguments[0]
result = {}
current = result
for arg, i in arguments when i + 1 < arguments.length
last = i + 2 is arguments.length
current = current[arg] = if last then arguments[arguments.length-1] else {}
result
test: ->
assertEquals {a:{b:12}}, create 'a', 'b', 12
assertEquals {a:3}, apply({a:1,b:2}, {a:3,b:undefined})
",
input: "runtime\\glass\\JSONMergePatch.coffee",
content: {
apply: function(target, patch) {
var key, value;
if ((target != null) && target !== patch && isPlainObject(patch) && !isPrimitive(target)) {
for (key in patch) {
value = patch[key];
if (value === void 0) {
delete target[key];
} else {
target[key] = apply(target[key], patch[key]);
}
}
return target;
} else {
return patch;
}
},
create: function() {
var arg, current, i, last, result, _i, _len;
if (arguments.length === 1) {
return arguments[0];
}
result = {};
current = result;
for (i = _i = 0, _len = arguments.length; _i < _len; i = ++_i) {
arg = arguments[i];
if (! (i + 1 < arguments.length)) {
continue;
}
last = i + 2 === arguments.length;
current = current[arg] = last ? arguments[arguments.length - 1] : {};
}
return result;
},
test: function() {
assertEquals({
a: {
b: 12
}
},
create('a', 'b', 12));
return assertEquals({
a: 3
},
apply({
a: 1,
b: 2
},
{
a: 3,
b: void 0
}));
},
name: "JSONMergePatch",
path: "glass.JSONMergePatch",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONMergePatch.apply": "apply",
"glass.JSONMergePatch.create": "create",
"glass.isPlainObject": "isPlainObject",
"glass.isPrimitive": "isPrimitive",
"glass.patch": "patch",
"glass.assertEquals": "assertEquals"
}
}
},
"glass.JSONPointer": {
source: "# json pointer implementation as per
# http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-05
_decodeStep: (step) -> step.replace(/~1/g, '/').replace(/~0/g, '~')
_getLastStep: (pointer) ->
_decodeStep pointer.substring(pointer.lastIndexOf('/') + 1)
_getParent: (pointer) ->
if not pointer?.length
null
else
pointer.substring(0, pointer.lastIndexOf('/'))
toArray: (pointer) ->
for step in pointer.substring(1).split('/')
_decodeStep step
get: (doc, pointer) ->
value = doc
if pointer.length
path = toArray pointer
for step in path when value?
value = value[step]
value
set: (doc, pointer, value) ->
parentPointer = _getParent pointer
if parentPointer?
parent = get doc, parentPointer
lastStep = _getLastStep pointer
parent[lastStep] = value
value
test: ->
assertEquals _getParent(\"/a/b/c\"), \"/a/b\"
assertEquals _getParent(\"/a\"), \"\"
assertEquals _getParent(\"\"), null
assertEquals _getLastStep(\"/a/b/c\"), \"c\"
assertEquals _getLastStep(\"/a~0~1\"), \"a~/\"
assertEquals _getLastStep(\"\"), \"\"
# tests as per spec
doc = {
\"foo\": [\"bar\", \"baz\"],
\"\": 0,
\"a/b\": 1,
\"c%d\": 2,
\"e^f\": 3,
\"g|h\": 4,
\"i\\\\j\": 5,
\"k\\\"l\": 6,
\" \": 7,
\"m~n\": 8
}
assertEquals get(doc, \"\"), doc
assertEquals get(doc, \"/foo\"), [\"bar\", \"baz\"]
assertEquals get(doc, \"/foo/0\"), \"bar\"
assertEquals get(doc, \"/\"), 0
assertEquals get(doc, \"/a~1b\"), 1
assertEquals get(doc, \"/c%d\"), 2
assertEquals get(doc, \"/e^f\"), 3
assertEquals get(doc, \"/g|h\"), 4
assertEquals get(doc, \"/i\\\\j\"), 5
assertEquals get(doc, \"/k\\\"l\"), 6
assertEquals get(doc, \"/ \"), 7
assertEquals get(doc, \"/m~0n\"), 8
# now test set
assertEquals set(doc, \"/\", 10), 10
assertEquals doc[\"\"], 10
assertEquals set(doc, \"/foo/0\", 10), 10
assertEquals doc.foo[0], 10",
input: "runtime\\glass\\JSONPointer.coffee",
content: {
toArray: function(pointer) {
var step, _i, _len, _ref, _results;
_ref = pointer.substring(1).split('/');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
step = _ref[_i];
_results.push(_decodeStep(step));
}
return _results;
},
get: function(doc, pointer) {
var path, step, value, _i, _len;
value = doc;
if (pointer.length) {
path = toArray(pointer);
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
}
return value;
},
set: function(doc, pointer, value) {
var lastStep, parent, parentPointer;
parentPointer = _getParent(pointer);
if (parentPointer != null) {
parent = get(doc, parentPointer);
lastStep = _getLastStep(pointer);
parent[lastStep] = value;
}
return value;
},
test: function() {
var doc;
assertEquals(_getParent("/a/b/c"), "/a/b");
assertEquals(_getParent("/a"), "");
assertEquals(_getParent(""), null);
assertEquals(_getLastStep("/a/b/c"), "c");
assertEquals(_getLastStep("/a~0~1"), "a~/");
assertEquals(_getLastStep(""), "");
doc = {
"foo": ["bar", "baz"],
"": 0,
"a/b": 1,
"c%d": 2,
"e^f": 3,
"g|h": 4,
"i\\j": 5,
"k\"l": 6,
" ": 7,
"m~n": 8
};
assertEquals(get(doc, ""), doc);
assertEquals(get(doc, "/foo"), ["bar", "baz"]);
assertEquals(get(doc, "/foo/0"), "bar");
assertEquals(get(doc, "/"), 0);
assertEquals(get(doc, "/a~1b"), 1);
assertEquals(get(doc, "/c%d"), 2);
assertEquals(get(doc, "/e^f"), 3);
assertEquals(get(doc, "/g|h"), 4);
assertEquals(get(doc, "/i\\j"), 5);
assertEquals(get(doc, "/k\"l"), 6);
assertEquals(get(doc, "/ "), 7);
assertEquals(get(doc, "/m~0n"), 8);
assertEquals(set(doc, "/", 10), 10);
assertEquals(doc[""], 10);
assertEquals(set(doc, "/foo/0", 10), 10);
return assertEquals(doc.foo[0], 10);
},
name: "JSONPointer",
path: "glass.JSONPointer",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONPointer._decodeStep": "_decodeStep",
"glass.JSONPointer._getLastStep": "_getLastStep",
"glass.JSONPointer._getParent": "_getParent",
"glass.JSONPointer.toArray": "toArray",
"glass.JSONPointer.get": "get",
"glass.JSONPointer.set": "set",
"glass.assertEquals": "assertEquals"
}
}
},
"glass.Observable": {
source: "properties:
is: (type) -> @constructor.implements[type.path ? type] is true
watchers:
serializable: false
watch: (property, watcher) ->
if isFunction property
watcher = property
property = ''
id = getId watcher
@patch 'watchers', property, id, watcher
# returns a function which will remove the watch
=> @patch 'watchers', property, getId(watcher), undefined
patch: (change) ->
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
try
JSONMergePatch.apply this, change
catch e
console.log e
finally
@notify change
return
notify: (change) ->
if @watchers?
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
for property, watchers of @watchers
if property.length is 0 or change.hasOwnProperty property
changeArg = if property.length is 0 then change else change[property]
for id, watcher of watchers
watcher this, changeArg
return
toJSON: ->
values =
class: @constructor.path
# serialize statically defined properties
for name, property of @constructor.properties
value = @[name]
if property.serializable isnt false and not isFunction(value)
values[name] = value
# serialize custom properties if allowed by schema
if @constructor.additionalProperties isnt false
for own name, value of @ when not isPrivate name
values[name] = value
values
toString: -> @toJSON()
test:
toJSON: ->
# I need this test later
# on a class that actually has serializable properties
a = new Observable
a.x = 12
a.y = ->
a.z = true
assertEquals a, {class:'glass.Observable', x:12,z:true}
watchAll: ->
# we should actually be able to watch ourselves get added to watchers
# this is very meta.
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch watcher
# now make sure we were called with our own watcher
assert watchArgs[0] is a
assert watchArgs[1]?.watchers?[\"\"]?
# reset watchArgs, and watch something else
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assertEquals a.a, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {a:{b:3}}
# now unwatch
unwatch()
# make sure universal watcher is now empty
assertEquals a.watchers[\"\"], {}
# now reset and do a new event, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
watchProperty: ->
# watch a property
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch \"foo\", watcher
# now make sure we were not called
assert watchArgs.length is 0
# reset watchArgs, and watch something else
a.patch \"foo\", \"b\", 3
assertEquals a.foo, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {b:3}
# now reset and do a different property, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
# now unwatch
unwatch()
# make sure we no longer see foo
watchArgs.length = 0
a.patch \"foo\", \"b\", 4
assert watchArgs.length is 0
",
input: "runtime\\glass\\Observable.coffee",
content: {
properties: {
is: {
value: function(type) {
var _ref;
return this.constructor["implements"][(_ref = type.path) != null ? _ref: type] === true;
},
name: "is"
},
watchers: {
serializable: false,
name: "watchers",
writable: true
},
watch: {
value: function(property, watcher) {
var id, _this = this;
if (isFunction(property)) {
watcher = property;
property = '';
}
id = getId(watcher);
this.patch('watchers', property, id, watcher);
return function() {
return _this.patch('watchers', property, getId(watcher), void 0);
};
},
name: "watch"
},
patch: {
value: function(change) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
try {
JSONMergePatch.apply(this, change);
} catch(e) {
console.log(e);
} finally {
this.notify(change);
}
},
name: "patch"
},
notify: {
value: function(change) {
var changeArg, id, property, watcher, watchers, _ref;
if (this.watchers != null) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
_ref = this.watchers;
for (property in _ref) {
watchers = _ref[property];
if (property.length === 0 || change.hasOwnProperty(property)) {
changeArg = property.length === 0 ? change: change[property];
for (id in watchers) {
watcher = watchers[id];
watcher(this, changeArg);
}
}
}
}
},
name: "notify"
},
toJSON: {
value: function() {
var name, property, value, values, _ref;
values = {
"class": this.constructor.path
};
_ref = this.constructor.properties;
for (name in _ref) {
property = _ref[name];
value = this[name];
if (property.serializable !== false && !isFunction(value)) {
values[name] = value;
}
}
if (this.constructor.additionalProperties !== false) {
for (name in this) {
if (!__hasProp.call(this, name)) continue;
value = this[name];
if (!isPrivate(name)) {
values[name] = value;
}
}
}
return values;
},
name: "toJSON"
},
toString: {
value: function() {
return this.toJSON();
},
name: "toString"
}
},
test: {
toJSON: function() {
var a;
a = new Observable;
a.x = 12;
a.y = function() {};
a.z = true;
return assertEquals(a, {
"class": 'glass.Observable',
x: 12,
z: true
});
},
watchAll: function() {
var a, unwatch, watchArgs, watcher, _ref, _ref1;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch(watcher);
assert(watchArgs[0] === a);
assert(((_ref = watchArgs[1]) != null ? (_ref1 = _ref.watchers) != null ? _ref1[""] : void 0 : void 0) != null);
watchArgs.length = 0;
a.patch("a", "b", 3);
assertEquals(a.a, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
a: {
b: 3
}
});
unwatch();
assertEquals(a.watchers[""], {});
watchArgs.length = 0;
a.patch("a", "b", 3);
return assert(watchArgs.length === 0);
},
watchProperty: function() {
var a, unwatch, watchArgs, watcher;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch("foo", watcher);
assert(watchArgs.length === 0);
a.patch("foo", "b", 3);
assertEquals(a.foo, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
b: 3
});
watchArgs.length = 0;
a.patch("a", "b", 3);
assert(watchArgs.length === 0);
unwatch();
watchArgs.length = 0;
a.patch("foo", "b", 4);
return assert(watchArgs.length === 0);
}
},
name: "Observable",
path: "glass.Observable",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONMergePatch": "JSONMergePatch",
"glass.isFunction": "isFunction",
"glass.isPrivate": "isPrivate",
"glass.values": "values",
"glass.patch": "patch",
"glass.assert": "assert",
"glass.assertEquals": "assertEquals",
"glass.getId": "getId"
}
}
},
glass: {
source: "require:
\tString: true
# runtime type tests
isFunction: (object) -> object? and typeof object is 'function'
isString: (object) -> object?.constructor is String
isArray: (object) -> Array.isArray object
isBoolean: (object) -> object? and typeof object is 'boolean'
isNumber: (object) -> object? and typeof object is 'number'
isObject: (object) -> typeof object is 'object'
isPlainObject: (object) -> object?.constructor is Object
isPrototype: (object) -> object? and object is object.constructor.prototype
isDate: (object) -> object?.constructor is Date
isPrimitive: (object) -> isString(object) or isBoolean(object) or isNumber(object) or isDate(object)
isPrivate: (property) -> property?[0] is '_'
# generic utility functions
values: (object) -> (value for key, value of object)
# generic patch method, uses patch method built into object if present
patch: (target, pathAndPatch...) ->
patch = JSONMergePatch.create.apply null, pathAndPatch
if isFunction target?.patch
target.patch patch
else
glass.JSONMergePatch.apply target, patch
# testing assertions
_getStackLocationInfo: (e, depth) ->
line = e.stack?.split('
')[depth]
return null unless line?
match = /\\(([\\w\\W]*?):(\\d+):(\\d+)\\)/.exec line
return {
file: match[1]
line: parseInt match[2]
column: parseInt match[3]
}
_throwAssertionFailure: (message) ->
try
throw new Error \"Assertion failed: \" + message
catch e
info = _getStackLocationInfo e, 3
if info?
_dumpFile info.file, info.line - 2, info.line + 2, info.line
throw e
_dumpFile: (file, from=1, to, highlight) ->
fs = require 'fs'
return unless fs?
try
content = fs.readFileSync(file).toString()
catch e
content = \"Source not found: #{e}\"
console.log '------------------------------------------------'
console.log file
console.log '------------------------------------------------'
number = 1
if content?
lines = content.split /
|
/
to ?= lines.length
for line in lines
lineNumber = number++
if lineNumber >= from and lineNumber <= to
num = String lineNumber
while num.length < 3
num += ' '
if lineNumber is highlight
`console.log(\"\\033[91m\" + num + \": \" + line + \"\\033[0m\");`
else
`console.log(num + \": \" + line);`
console.log '------------------------------------------------'
assert: (a) ->
_throwAssertionFailure JSON.stringify(a) unless a
assertTrue: (a) ->
_throwAssertionFailure JSON.stringify(a) + \" != true\" unless a is true
assertEquals: (a, b) ->
if JSON.stringify(a) isnt JSON.stringify(b)
_throwAssertionFailure JSON.stringify(a) + ' != ' + JSON.stringify(b)
# gets a unique string identifier for any object
getId:
do: ->
counter = 0
(a) ->
if a is null
return '__null__'
if a is undefined
return '__undefined__'
if typeof a is 'object' or typeof a is 'function'
return a.id ?= '__' + (counter++) + '__'
# 12 == \"12\" under this technique
return a.toString()
getType: (path) ->
array = if isArray path then path else path.split '.'
value = global
for step in path when value?
value = value[step]
throw new Error \"Type not found: #{path}\" unless isFunction value
value
test:
values: ->
assertEquals values({a:1,b:3,c:2}), [1,3,2]
patch: ->
x = {a:{foo:1,bar:3},b:2}
patch x, 'a', 'foo', 5
assertEquals x.a.foo, 5
",
input: "runtime\\glass.coffee",
content: {
require: {
String: "String"
},
isFunction: function(object) {
return (object != null) && typeof object === 'function';
},
isString: function(object) {
return (object != null ? object.constructor: void 0) === String;
},
isArray: function(object) {
return Array.isArray(object);
},
isBoolean: function(object) {
return (object != null) && typeof object === 'boolean';
},
isNumber: function(object) {
return (object != null) && typeof object === 'number';
},
isObject: function(object) {
return typeof object === 'object';
},
isPlainObject: function(object) {
return (object != null ? object.constructor: void 0) === Object;
},
isPrototype: function(object) {
return (object != null) && object === object.constructor.prototype;
},
isDate: function(object) {
return (object != null ? object.constructor: void 0) === Date;
},
isPrimitive: function(object) {
return isString(object) || isBoolean(object) || isNumber(object) || isDate(object);
},
isPrivate: function(property) {
return (property != null ? property[0] : void 0) === '_';
},
values: function(object) {
var key, value, _results;
_results = [];
for (key in object) {
value = object[key];
_results.push(value);
}
return _results;
},
patch: function() {
var patch, pathAndPatch, target;
target = arguments[0],
pathAndPatch = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
patch = JSONMergePatch.create.apply(null, pathAndPatch);
if (isFunction(target != null ? target.patch: void 0)) {
return target.patch(patch);
} else {
return glass.JSONMergePatch.apply(target, patch);
}
},
assert: function(a) {
if (!a) {
return _throwAssertionFailure(JSON.stringify(a));
}
},
assertTrue: function(a) {
if (a !== true) {
return _throwAssertionFailure(JSON.stringify(a) + " != true");
}
},
assertEquals: function(a, b) {
if (JSON.stringify(a) !== JSON.stringify(b)) {
return _throwAssertionFailure(JSON.stringify(a) + ' != ' + JSON.stringify(b));
}
},
getId: {
do: function() {
var counter;
counter = 0;
return function(a) {
var _ref;
if (a === null) {
return '__null__';
}
if (a === void 0) {
return '__undefined__';
}
if (typeof a === 'object' || typeof a === 'function') {
return (_ref = a.id) != null ? _ref: a.id = '__' + (counter++) + '__';
}
return a.toString();
};
}
},
getType: function(path) {
var array, step, value, _i, _len;
array = isArray(path) ? path: path.split('.');
value = global;
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
if (!isFunction(value)) {
throw new Error("Type not found: " + path);
}
return value;
},
test: {
values: function() {
return assertEquals(values({
a: 1,
b: 3,
c: 2
}), [1, 3, 2]);
},
patch: function() {
var x;
x = {
a: {
foo: 1,
bar: 3
},
b: 2
};
patch(x, 'a', 'foo', 5);
return assertEquals(x.a.foo, 5);
}
},
name: "glass",
path: "glass",
namespace: "",
import: {
"glass.JSONMergePatch": "JSONMergePatch",
"glass.isFunction": "isFunction",
"glass.isString": "isString",
"glass.isArray": "isArray",
"glass.isBoolean": "isBoolean",
"glass.isNumber": "isNumber",
"glass.isDate": "isDate",
"glass.values": "values",
"glass.patch": "patch",
"glass._getStackLocationInfo": "_getStackLocationInfo",
"glass._throwAssertionFailure": "_throwAssertionFailure",
"glass._dumpFile": "_dumpFile",
"glass.assertEquals": "assertEquals"
}
}
},
String: {
source: "extension: true
properties:
\tstartsWith: (s) -> @slice(0,s.length) is s
\tendsWith: (s) -> @slice(-s.length) is s
\tcontains: (s) -> @indexOf(s) >= 0
\ttoArray: () -> @split ''",
input: "runtime\\String.coffee",
content: {
extension: true,
properties: {
startsWith: {
value: function(s) {
return this.slice(0, s.length) === s;
},
name: "startsWith"
},
endsWith: {
value: function(s) {
return this.slice( - s.length) === s;
},
name: "endsWith"
},
contains: {
value: function(s) {
return this.indexOf(s) >= 0;
},
name: "contains"
},
toArray: {
value: function() {
return this.split('');
},
name: "toArray"
}
},
name: "String",
path: "String",
namespace: "",
require: {},
import: {}
}
}
}
} | {
options: {
input: {
dir: "runtime",
match: /\.(coffee|pegjs)$/
},
output: {
dir: "www/js"
},
script: {
includes: "www/includes.html",
prefix: "/js/"
},
module: {
main: "glass.js",
prefix: "./www/js/"
},
debug: "buildlog.html",
test: "glass.allTests",
addon: {
pregenerate: {
addUri: function(schema) {
var content, type, typeName, _ref2, _ref3;
_ref2 = schema.types;
for (typeName in _ref2) {
type = _ref2[typeName];
content = type.content;
if (content.extension) {
continue;
}
if ((_ref3 = content.uri) == null) {
content.uri = "global:/" + (content.path.replace(/\./g, '/'));
}
}
return schema;
}
}
},
namespace: ""
},
types: {
String: {
source: "extension: true
properties:
\tstartsWith: (s) -> @slice(0,s.length) is s
\tendsWith: (s) -> @slice(-s.length) is s
\tcontains: (s) -> @indexOf(s) >= 0
\ttoArray: () -> @split ''",
input: "runtime\\String.coffee",
content: {
extension: true,
properties: {
startsWith: {
value: function(s) {
return this.slice(0, s.length) === s;
},
name: "startsWith"
},
endsWith: {
value: function(s) {
return this.slice( - s.length) === s;
},
name: "endsWith"
},
contains: {
value: function(s) {
return this.indexOf(s) >= 0;
},
name: "contains"
},
toArray: {
value: function() {
return this.split('');
},
name: "toArray"
}
},
name: "String",
path: "String",
namespace: "",
require: {},
import: {}
}
},
glass: {
source: "require:
\tString: true
# runtime type tests
isFunction: (object) -> object? and typeof object is 'function'
isString: (object) -> object?.constructor is String
isArray: (object) -> Array.isArray object
isBoolean: (object) -> object? and typeof object is 'boolean'
isNumber: (object) -> object? and typeof object is 'number'
isObject: (object) -> typeof object is 'object'
isPlainObject: (object) -> object?.constructor is Object
isPrototype: (object) -> object? and object is object.constructor.prototype
isDate: (object) -> object?.constructor is Date
isPrimitive: (object) -> isString(object) or isBoolean(object) or isNumber(object) or isDate(object)
isPrivate: (property) -> property?[0] is '_'
# generic utility functions
values: (object) -> (value for key, value of object)
# generic patch method, uses patch method built into object if present
patch: (target, pathAndPatch...) ->
patch = JSONMergePatch.create.apply null, pathAndPatch
if isFunction target?.patch
target.patch patch
else
glass.JSONMergePatch.apply target, patch
# testing assertions
_getStackLocationInfo: (e, depth) ->
line = e.stack?.split('
')[depth]
return null unless line?
match = /\\(([\\w\\W]*?):(\\d+):(\\d+)\\)/.exec line
return {
file: match[1]
line: parseInt match[2]
column: parseInt match[3]
}
_throwAssertionFailure: (message) ->
try
throw new Error \"Assertion failed: \" + message
catch e
info = _getStackLocationInfo e, 3
if info?
_dumpFile info.file, info.line - 2, info.line + 2, info.line
throw e
_dumpFile: (file, from=1, to, highlight) ->
fs = require 'fs'
return unless fs?
try
content = fs.readFileSync(file).toString()
catch e
content = \"Source not found: #{e}\"
console.log '------------------------------------------------'
console.log file
console.log '------------------------------------------------'
number = 1
if content?
lines = content.split /
|
/
to ?= lines.length
for line in lines
lineNumber = number++
if lineNumber >= from and lineNumber <= to
num = String lineNumber
while num.length < 3
num += ' '
if lineNumber is highlight
`console.log(\"\\033[91m\" + num + \": \" + line + \"\\033[0m\");`
else
`console.log(num + \": \" + line);`
console.log '------------------------------------------------'
assert: (a) ->
_throwAssertionFailure JSON.stringify(a) unless a
assertTrue: (a) ->
_throwAssertionFailure JSON.stringify(a) + \" != true\" unless a is true
assertEquals: (a, b) ->
if JSON.stringify(a) isnt JSON.stringify(b)
_throwAssertionFailure JSON.stringify(a) + ' != ' + JSON.stringify(b)
# gets a unique string identifier for any object
getId:
do: ->
counter = 0
(a) ->
if a is null
return '__null__'
if a is undefined
return '__undefined__'
if typeof a is 'object' or typeof a is 'function'
return a.id ?= '__' + (counter++) + '__'
# 12 == \"12\" under this technique
return a.toString()
getType: (path) ->
array = if isArray path then path else path.split '.'
value = global
for step in path when value?
value = value[step]
throw new Error \"Type not found: #{path}\" unless isFunction value
value
test:
values: ->
assertEquals values({a:1,b:3,c:2}), [1,3,2]
patch: ->
x = {a:{foo:1,bar:3},b:2}
patch x, 'a', 'foo', 5
assertEquals x.a.foo, 5
",
input: "runtime\\glass.coffee",
content: {
require: {
String: "String"
},
isFunction: function(object) {
return (object != null) && typeof object === 'function';
},
isString: function(object) {
return (object != null ? object.constructor: void 0) === String;
},
isArray: function(object) {
return Array.isArray(object);
},
isBoolean: function(object) {
return (object != null) && typeof object === 'boolean';
},
isNumber: function(object) {
return (object != null) && typeof object === 'number';
},
isObject: function(object) {
return typeof object === 'object';
},
isPlainObject: function(object) {
return (object != null ? object.constructor: void 0) === Object;
},
isPrototype: function(object) {
return (object != null) && object === object.constructor.prototype;
},
isDate: function(object) {
return (object != null ? object.constructor: void 0) === Date;
},
isPrimitive: function(object) {
return isString(object) || isBoolean(object) || isNumber(object) || isDate(object);
},
isPrivate: function(property) {
return (property != null ? property[0] : void 0) === '_';
},
values: function(object) {
var key, value, _results;
_results = [];
for (key in object) {
value = object[key];
_results.push(value);
}
return _results;
},
patch: function() {
var patch, pathAndPatch, target;
target = arguments[0],
pathAndPatch = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
patch = JSONMergePatch.create.apply(null, pathAndPatch);
if (isFunction(target != null ? target.patch: void 0)) {
return target.patch(patch);
} else {
return glass.JSONMergePatch.apply(target, patch);
}
},
assert: function(a) {
if (!a) {
return _throwAssertionFailure(JSON.stringify(a));
}
},
assertTrue: function(a) {
if (a !== true) {
return _throwAssertionFailure(JSON.stringify(a) + " != true");
}
},
assertEquals: function(a, b) {
if (JSON.stringify(a) !== JSON.stringify(b)) {
return _throwAssertionFailure(JSON.stringify(a) + ' != ' + JSON.stringify(b));
}
},
getId: {
do: function() {
var counter;
counter = 0;
return function(a) {
var _ref;
if (a === null) {
return '__null__';
}
if (a === void 0) {
return '__undefined__';
}
if (typeof a === 'object' || typeof a === 'function') {
return (_ref = a.id) != null ? _ref: a.id = '__' + (counter++) + '__';
}
return a.toString();
};
}
},
getType: function(path) {
var array, step, value, _i, _len;
array = isArray(path) ? path: path.split('.');
value = global;
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
if (!isFunction(value)) {
throw new Error("Type not found: " + path);
}
return value;
},
test: {
values: function() {
return assertEquals(values({
a: 1,
b: 3,
c: 2
}), [1, 3, 2]);
},
patch: function() {
var x;
x = {
a: {
foo: 1,
bar: 3
},
b: 2
};
patch(x, 'a', 'foo', 5);
return assertEquals(x.a.foo, 5);
}
},
name: "glass",
path: "glass",
namespace: "",
import: {
"glass.JSONMergePatch": "JSONMergePatch",
"glass.isFunction": "isFunction",
"glass.isString": "isString",
"glass.isArray": "isArray",
"glass.isBoolean": "isBoolean",
"glass.isNumber": "isNumber",
"glass.isDate": "isDate",
"glass.values": "values",
"glass.patch": "patch",
"glass._getStackLocationInfo": "_getStackLocationInfo",
"glass._throwAssertionFailure": "_throwAssertionFailure",
"glass._dumpFile": "_dumpFile",
"glass.assertEquals": "assertEquals"
}
}
},
"glass.Expression": {
source: "constructor: (op, args) ->
@op = op
@args = args if args?
@
properties:
op:
type: 'string'
args:
type: 'array'
test: ->
return
peg = require 'pegjs'
fs = require 'fs'
parserSource = fs.readFileSync 'runtime/glass/Expression/_parser.pegjs', 'utf8'
parser = peg.buildParser parserSource
tests =
\"a.b.c\": {op:\"get\",args:[{op:\"get\",args:[{op:\"ref\",args:[\"a\"]},\"b\"]},\"c\"]}
\"a.1\": {op:\"get\",args:[{op:\"ref\",args:[\"a\"]},1]}
\"true\": true
\"false\": false
\"45.8\": 45.8
\"(45.8)\": 45.8
\"((45.8))\": 45.8
\"alpha\": {op:\"ref\",args:[\"alpha\"]}
\"35 + true * 2\": {op:\"+\", args:[35, {op:\"*\", args:[true,2]}]}
\" 5 * ( 2 + 2 ) \": {op:\"*\", args:[5, {op:\"+\", args:[2,2]}]}
\" ! ! true\": {op:\"!\",args:[{op:\"!\",args:[true]}]}
\"5 + -x\": {op:\"+\",args:[5,{op:\"-\",args:[{op:\"ref\",args:[\"x\"]}]}]}
\"true == 5 >= 2\": {op:\"==\",args:[true,{op:\">=\",args:[5,2]}]}
\"1 or 2 and 3\": {op:\"or\",args:[1,{op:\"and\",args:[2,3]}]}
\"1 ? 2 : 3\": {op:\"?:\",args:[1,2,3]}
\"1 ? 2 : 3 ? 4 : 5\" : {op:\"?:\",args:[1,2,{op:\"?:\",args:[3,4,5]}]}
\"a()(1,2)\" : {op:\"call\",args:[{op:\"call\",args:[{op:\"ref\",args:[\"a\"]},[]]},[1,2]]}
\"@\" : {op:\"this\"}
\"@foo\" : {op:\"get\",args:[{op:\"this\"},\"foo\"]}
'\"hello\"': \"hello\"
'\"\\\\t\\
\\
\\\\b\\\\\\\\foo\\\\\\/\"' : \"\\t
\\b\\\\foo\\/\"
\"[]\": {op:\"array\",args:[]}
\"[1,2]\": {op:\"array\",args:[1,2]}
\"[1+2]\": {op:\"array\",args:[{op:\"+\",args:[1,2]}]}
\"{}\": {op:\"object\",args:[]}
'{\"a\":2}': {op:\"object\",args:[[\"a\",2]]}
'{\"a\":2,\"b\":1+2}': {op:\"object\",args:[[\"a\",2],[\"b\",{op:\"+\",args:[1,2]}]]}
'@\"alpha\"': {op:\"get\",args:[{op:\"this\"},\"alpha\"]}
'*': {op:\"values\",args:[]}
'*.*': {op:\"values\",args:[{op:\"values\",args:[]}]}
\"foo.*\": {op:\"values\",args:[{op:\"ref\",args:[\"foo\"]}]}
\"..\": {op:\"ancestor\",args:[1]}
\"...\": {op:\"ancestor\",args:[2]}
\"@*{1+2}\": {op:\"eval\",args:[{op:\"values\",args:[{op:\"this\"}]},{op:\"+\",args:[1,2]}]}
\"/\": {op:\"root\"}
\"/foo\": {op:\"get\",args:[{op:\"root\"},\"foo\"]}
\"/*\": {op:\"values\",args:[{op:\"root\"}]}
for text, expected of tests
result = parser.parse text
if JSON.stringify(result) is JSON.stringify(expected)
console.log 'Pass: ' + text
else
console.log text, JSON.stringify result
return
",
input: "runtime\\glass\\Expression.coffee",
content: {
constructor: function(op, args) {
this.op = op;
if (args != null) {
this.args = args;
}
return this;
},
properties: {
op: {
type: "string",
name: "op",
writable: true
},
args: {
type: "array",
name: "args",
writable: true
}
},
test: function() {
var expected, fs, parser, parserSource, peg, result, tests, text;
return;
peg = require('pegjs');
fs = require('fs');
parserSource = fs.readFileSync('runtime/glass/Expression/_parser.pegjs', 'utf8');
parser = peg.buildParser(parserSource);
tests = {
"a.b.c": {
op: "get",
args: [{
op: "get",
args: [{
op: "ref",
args: ["a"]
},
"b"]
},
"c"]
},
"a.1": {
op: "get",
args: [{
op: "ref",
args: ["a"]
},
1]
},
"true": true,
"false": false,
"45.8": 45.8,
"(45.8)": 45.8,
"((45.8))": 45.8,
"alpha": {
op: "ref",
args: ["alpha"]
},
"35 + true * 2": {
op: "+",
args: [35, {
op: "*",
args: [true, 2]
}]
},
" 5 * ( 2 + 2 ) ": {
op: "*",
args: [5, {
op: "+",
args: [2, 2]
}]
},
" ! ! true": {
op: "!",
args: [{
op: "!",
args: [true]
}]
},
"5 + -x": {
op: "+",
args: [5, {
op: "-",
args: [{
op: "ref",
args: ["x"]
}]
}]
},
"true == 5 >= 2": {
op: "==",
args: [true, {
op: ">=",
args: [5, 2]
}]
},
"1 or 2 and 3": {
op: "or",
args: [1, {
op: "and",
args: [2, 3]
}]
},
"1 ? 2 : 3": {
op: "?:",
args: [1, 2, 3]
},
"1 ? 2 : 3 ? 4 : 5": {
op: "?:",
args: [1, 2, {
op: "?:",
args: [3, 4, 5]
}]
},
"a()(1,2)": {
op: "call",
args: [{
op: "call",
args: [{
op: "ref",
args: ["a"]
},
[]]
},
[1, 2]]
},
"@": {
op: "this"
},
"@foo": {
op: "get",
args: [{
op: "this"
},
"foo"]
},
'"hello"': "hello",
'"\\t
\\b\\\\foo\\\/"': "\t
\b\\foo\/",
"[]": {
op: "array",
args: []
},
"[1,2]": {
op: "array",
args: [1, 2]
},
"[1+2]": {
op: "array",
args: [{
op: "+",
args: [1, 2]
}]
},
"{}": {
op: "object",
args: []
},
'{"a":2}': {
op: "object",
args: [["a", 2]]
},
'{"a":2,"b":1+2}': {
op: "object",
args: [["a", 2], ["b", {
op: "+",
args: [1, 2]
}]]
},
'@"alpha"': {
op: "get",
args: [{
op: "this"
},
"alpha"]
},
'*': {
op: "values",
args: []
},
'*.*': {
op: "values",
args: [{
op: "values",
args: []
}]
},
"foo.*": {
op: "values",
args: [{
op: "ref",
args: ["foo"]
}]
},
"..": {
op: "ancestor",
args: [1]
},
"...": {
op: "ancestor",
args: [2]
},
"@*{1+2}": {
op: "eval",
args: [{
op: "values",
args: [{
op: "this"
}]
},
{
op: "+",
args: [1, 2]
}]
},
"/": {
op: "root"
},
"/foo": {
op: "get",
args: [{
op: "root"
},
"foo"]
},
"/*": {
op: "values",
args: [{
op: "root"
}]
}
};
for (text in tests) {
expected = tests[text];
result = parser.parse(text);
if (JSON.stringify(result) === JSON.stringify(expected)) {
console.log('Pass: ' + text);
} else {
console.log(text, JSON.stringify(result));
}
}
},
name: "Expression",
path: "glass.Expression",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.Expression._parser": "_parser",
"glass.values": "values"
}
}
},
"glass.JSONMergePatch": {
source: "
# applies a patch to the target object and returns the resulting target
apply: (target, patch) ->
if target? and target isnt patch and isPlainObject(patch) and not isPrimitive(target)
for key, value of patch
if value is undefined
delete target[key]
else
target[key] = apply target[key], patch[key]
return target
else
return patch
# (path1, path2, path3.., patch) ->
create: ->
if arguments.length is 1
return arguments[0]
result = {}
current = result
for arg, i in arguments when i + 1 < arguments.length
last = i + 2 is arguments.length
current = current[arg] = if last then arguments[arguments.length-1] else {}
result
test: ->
assertEquals {a:{b:12}}, create 'a', 'b', 12
assertEquals {a:3}, apply({a:1,b:2}, {a:3,b:undefined})
",
input: "runtime\\glass\\JSONMergePatch.coffee",
content: {
apply: function(target, patch) {
var key, value;
if ((target != null) && target !== patch && isPlainObject(patch) && !isPrimitive(target)) {
for (key in patch) {
value = patch[key];
if (value === void 0) {
delete target[key];
} else {
target[key] = apply(target[key], patch[key]);
}
}
return target;
} else {
return patch;
}
},
create: function() {
var arg, current, i, last, result, _i, _len;
if (arguments.length === 1) {
return arguments[0];
}
result = {};
current = result;
for (i = _i = 0, _len = arguments.length; _i < _len; i = ++_i) {
arg = arguments[i];
if (! (i + 1 < arguments.length)) {
continue;
}
last = i + 2 === arguments.length;
current = current[arg] = last ? arguments[arguments.length - 1] : {};
}
return result;
},
test: function() {
assertEquals({
a: {
b: 12
}
},
create('a', 'b', 12));
return assertEquals({
a: 3
},
apply({
a: 1,
b: 2
},
{
a: 3,
b: void 0
}));
},
name: "JSONMergePatch",
path: "glass.JSONMergePatch",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONMergePatch.apply": "apply",
"glass.JSONMergePatch.create": "create",
"glass.isPlainObject": "isPlainObject",
"glass.isPrimitive": "isPrimitive",
"glass.patch": "patch",
"glass.assertEquals": "assertEquals"
}
}
},
"glass.JSONPointer": {
source: "# json pointer implementation as per
# http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-05
_decodeStep: (step) -> step.replace(/~1/g, '/').replace(/~0/g, '~')
_getLastStep: (pointer) ->
_decodeStep pointer.substring(pointer.lastIndexOf('/') + 1)
_getParent: (pointer) ->
if not pointer?.length
null
else
pointer.substring(0, pointer.lastIndexOf('/'))
toArray: (pointer) ->
for step in pointer.substring(1).split('/')
_decodeStep step
get: (doc, pointer) ->
value = doc
if pointer.length
path = toArray pointer
for step in path when value?
value = value[step]
value
set: (doc, pointer, value) ->
parentPointer = _getParent pointer
if parentPointer?
parent = get doc, parentPointer
lastStep = _getLastStep pointer
parent[lastStep] = value
value
test: ->
assertEquals _getParent(\"/a/b/c\"), \"/a/b\"
assertEquals _getParent(\"/a\"), \"\"
assertEquals _getParent(\"\"), null
assertEquals _getLastStep(\"/a/b/c\"), \"c\"
assertEquals _getLastStep(\"/a~0~1\"), \"a~/\"
assertEquals _getLastStep(\"\"), \"\"
# tests as per spec
doc = {
\"foo\": [\"bar\", \"baz\"],
\"\": 0,
\"a/b\": 1,
\"c%d\": 2,
\"e^f\": 3,
\"g|h\": 4,
\"i\\\\j\": 5,
\"k\\\"l\": 6,
\" \": 7,
\"m~n\": 8
}
assertEquals get(doc, \"\"), doc
assertEquals get(doc, \"/foo\"), [\"bar\", \"baz\"]
assertEquals get(doc, \"/foo/0\"), \"bar\"
assertEquals get(doc, \"/\"), 0
assertEquals get(doc, \"/a~1b\"), 1
assertEquals get(doc, \"/c%d\"), 2
assertEquals get(doc, \"/e^f\"), 3
assertEquals get(doc, \"/g|h\"), 4
assertEquals get(doc, \"/i\\\\j\"), 5
assertEquals get(doc, \"/k\\\"l\"), 6
assertEquals get(doc, \"/ \"), 7
assertEquals get(doc, \"/m~0n\"), 8
# now test set
assertEquals set(doc, \"/\", 10), 10
assertEquals doc[\"\"], 10
assertEquals set(doc, \"/foo/0\", 10), 10
assertEquals doc.foo[0], 10",
input: "runtime\\glass\\JSONPointer.coffee",
content: {
toArray: function(pointer) {
var step, _i, _len, _ref, _results;
_ref = pointer.substring(1).split('/');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
step = _ref[_i];
_results.push(_decodeStep(step));
}
return _results;
},
get: function(doc, pointer) {
var path, step, value, _i, _len;
value = doc;
if (pointer.length) {
path = toArray(pointer);
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
}
return value;
},
set: function(doc, pointer, value) {
var lastStep, parent, parentPointer;
parentPointer = _getParent(pointer);
if (parentPointer != null) {
parent = get(doc, parentPointer);
lastStep = _getLastStep(pointer);
parent[lastStep] = value;
}
return value;
},
test: function() {
var doc;
assertEquals(_getParent("/a/b/c"), "/a/b");
assertEquals(_getParent("/a"), "");
assertEquals(_getParent(""), null);
assertEquals(_getLastStep("/a/b/c"), "c");
assertEquals(_getLastStep("/a~0~1"), "a~/");
assertEquals(_getLastStep(""), "");
doc = {
"foo": ["bar", "baz"],
"": 0,
"a/b": 1,
"c%d": 2,
"e^f": 3,
"g|h": 4,
"i\\j": 5,
"k\"l": 6,
" ": 7,
"m~n": 8
};
assertEquals(get(doc, ""), doc);
assertEquals(get(doc, "/foo"), ["bar", "baz"]);
assertEquals(get(doc, "/foo/0"), "bar");
assertEquals(get(doc, "/"), 0);
assertEquals(get(doc, "/a~1b"), 1);
assertEquals(get(doc, "/c%d"), 2);
assertEquals(get(doc, "/e^f"), 3);
assertEquals(get(doc, "/g|h"), 4);
assertEquals(get(doc, "/i\\j"), 5);
assertEquals(get(doc, "/k\"l"), 6);
assertEquals(get(doc, "/ "), 7);
assertEquals(get(doc, "/m~0n"), 8);
assertEquals(set(doc, "/", 10), 10);
assertEquals(doc[""], 10);
assertEquals(set(doc, "/foo/0", 10), 10);
return assertEquals(doc.foo[0], 10);
},
name: "JSONPointer",
path: "glass.JSONPointer",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONPointer._decodeStep": "_decodeStep",
"glass.JSONPointer._getLastStep": "_getLastStep",
"glass.JSONPointer._getParent": "_getParent",
"glass.JSONPointer.toArray": "toArray",
"glass.JSONPointer.get": "get",
"glass.JSONPointer.set": "set",
"glass.assertEquals": "assertEquals"
}
}
},
"glass.Observable": {
source: "properties:
is: (type) -> @constructor.implements[type.path ? type] is true
watchers:
serializable: false
watch: (property, watcher) ->
if isFunction property
watcher = property
property = ''
id = getId watcher
@patch 'watchers', property, id, watcher
# returns a function which will remove the watch
=> @patch 'watchers', property, getId(watcher), undefined
patch: (change) ->
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
try
JSONMergePatch.apply this, change
catch e
console.log e
finally
@notify change
return
notify: (change) ->
if @watchers?
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
for property, watchers of @watchers
if property.length is 0 or change.hasOwnProperty property
changeArg = if property.length is 0 then change else change[property]
for id, watcher of watchers
watcher this, changeArg
return
toJSON: ->
values =
class: @constructor.path
# serialize statically defined properties
for name, property of @constructor.properties
value = @[name]
if property.serializable isnt false and not isFunction(value)
values[name] = value
# serialize custom properties if allowed by schema
if @constructor.additionalProperties isnt false
for own name, value of @ when not isPrivate name
values[name] = value
values
toString: -> @toJSON()
test:
toJSON: ->
# I need this test later
# on a class that actually has serializable properties
a = new Observable
a.x = 12
a.y = ->
a.z = true
assertEquals a, {class:'glass.Observable', x:12,z:true}
watchAll: ->
# we should actually be able to watch ourselves get added to watchers
# this is very meta.
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch watcher
# now make sure we were called with our own watcher
assert watchArgs[0] is a
assert watchArgs[1]?.watchers?[\"\"]?
# reset watchArgs, and watch something else
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assertEquals a.a, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {a:{b:3}}
# now unwatch
unwatch()
# make sure universal watcher is now empty
assertEquals a.watchers[\"\"], {}
# now reset and do a new event, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
watchProperty: ->
# watch a property
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch \"foo\", watcher
# now make sure we were not called
assert watchArgs.length is 0
# reset watchArgs, and watch something else
a.patch \"foo\", \"b\", 3
assertEquals a.foo, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {b:3}
# now reset and do a different property, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
# now unwatch
unwatch()
# make sure we no longer see foo
watchArgs.length = 0
a.patch \"foo\", \"b\", 4
assert watchArgs.length is 0
",
input: "runtime\\glass\\Observable.coffee",
content: {
properties: {
is: {
value: function(type) {
var _ref;
return this.constructor["implements"][(_ref = type.path) != null ? _ref: type] === true;
},
name: "is"
},
watchers: {
serializable: false,
name: "watchers",
writable: true
},
watch: {
value: function(property, watcher) {
var id, _this = this;
if (isFunction(property)) {
watcher = property;
property = '';
}
id = getId(watcher);
this.patch('watchers', property, id, watcher);
return function() {
return _this.patch('watchers', property, getId(watcher), void 0);
};
},
name: "watch"
},
patch: {
value: function(change) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
try {
JSONMergePatch.apply(this, change);
} catch(e) {
console.log(e);
} finally {
this.notify(change);
}
},
name: "patch"
},
notify: {
value: function(change) {
var changeArg, id, property, watcher, watchers, _ref;
if (this.watchers != null) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
_ref = this.watchers;
for (property in _ref) {
watchers = _ref[property];
if (property.length === 0 || change.hasOwnProperty(property)) {
changeArg = property.length === 0 ? change: change[property];
for (id in watchers) {
watcher = watchers[id];
watcher(this, changeArg);
}
}
}
}
},
name: "notify"
},
toJSON: {
value: function() {
var name, property, value, values, _ref;
values = {
"class": this.constructor.path
};
_ref = this.constructor.properties;
for (name in _ref) {
property = _ref[name];
value = this[name];
if (property.serializable !== false && !isFunction(value)) {
values[name] = value;
}
}
if (this.constructor.additionalProperties !== false) {
for (name in this) {
if (!__hasProp.call(this, name)) continue;
value = this[name];
if (!isPrivate(name)) {
values[name] = value;
}
}
}
return values;
},
name: "toJSON"
},
toString: {
value: function() {
return this.toJSON();
},
name: "toString"
}
},
test: {
toJSON: function() {
var a;
a = new Observable;
a.x = 12;
a.y = function() {};
a.z = true;
return assertEquals(a, {
"class": 'glass.Observable',
x: 12,
z: true
});
},
watchAll: function() {
var a, unwatch, watchArgs, watcher, _ref, _ref1;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch(watcher);
assert(watchArgs[0] === a);
assert(((_ref = watchArgs[1]) != null ? (_ref1 = _ref.watchers) != null ? _ref1[""] : void 0 : void 0) != null);
watchArgs.length = 0;
a.patch("a", "b", 3);
assertEquals(a.a, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
a: {
b: 3
}
});
unwatch();
assertEquals(a.watchers[""], {});
watchArgs.length = 0;
a.patch("a", "b", 3);
return assert(watchArgs.length === 0);
},
watchProperty: function() {
var a, unwatch, watchArgs, watcher;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch("foo", watcher);
assert(watchArgs.length === 0);
a.patch("foo", "b", 3);
assertEquals(a.foo, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
b: 3
});
watchArgs.length = 0;
a.patch("a", "b", 3);
assert(watchArgs.length === 0);
unwatch();
watchArgs.length = 0;
a.patch("foo", "b", 4);
return assert(watchArgs.length === 0);
}
},
name: "Observable",
path: "glass.Observable",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONMergePatch": "JSONMergePatch",
"glass.isFunction": "isFunction",
"glass.isPrivate": "isPrivate",
"glass.values": "values",
"glass.patch": "patch",
"glass.assert": "assert",
"glass.assertEquals": "assertEquals",
"glass.getId": "getId"
}
}
},
"glass.Component": {
source: "extends: 'Observable'
constructor: (properties) ->
@patch properties
# now site ourselves on our parent
if @parent
id = getId @
patch @parent, id, @
@
properties:
id:
description: 'string which uniquely identifies this component within its parent'
type: 'string'
parent:
description: 'the object that contains this component'
serializable: false
type: 'object'
disposed: false
dispose: -> @patch 'disposed', true
notify: (change) ->
Observable.prototype.notify.apply this, arguments
if change?.disposed
# dispose of any disposable children
for id, child of @ when child?.parent is @
child.dispose?()
# remove self from parent
if @id and @parent
patch @parent, @id, undefined
return
test:
lifecycle: ->
parent = new Component
assert not parent.id?
assert not parent.parent?
child = new Component parent:parent
# id should be automatically assigned
assert isString child.id
assert parent is child.parent
assert parent[child.id] is child
assert parent.hasOwnProperty child.id
parent.dispose()
assert child.disposed is true
assert not parent.hasOwnProperty child.id
nonEnumerability: ->
visibleKeys = (key for key of new Component)
assertEquals visibleKeys, []",
input: "runtime\\glass\\Component.coffee",
content: {
extends: ["glass.Observable"],
constructor: function(properties) {
var id;
this.patch(properties);
if (this.parent) {
id = getId(this);
patch(this.parent, id, this);
}
return this;
},
properties: {
id: {
description: "string which uniquely identifies this component within its parent",
type: "string",
name: "id",
writable: true
},
parent: {
description: "the object that contains this component",
serializable: false,
type: "object",
name: "parent",
writable: true
},
disposed: {
value: false,
name: "disposed",
writable: true
},
dispose: {
value: function() {
return this.patch('disposed', true);
},
name: "dispose"
},
notify: {
value: function(change) {
var child, id;
Observable.prototype.notify.apply(this, arguments);
if (change != null ? change.disposed: void 0) {
for (id in this) {
child = this[id];
if ((child != null ? child.parent: void 0) === this) {
if (typeof child.dispose === "function") {
child.dispose();
}
}
}
if (this.id && this.parent) {
patch(this.parent, this.id, void 0);
}
}
},
name: "notify"
}
},
test: {
lifecycle: function() {
var child, parent;
parent = new Component;
assert(!(parent.id != null));
assert(!(parent.parent != null));
child = new Component({
parent: parent
});
assert(isString(child.id));
assert(parent === child.parent);
assert(parent[child.id] === child);
assert(parent.hasOwnProperty(child.id));
parent.dispose();
assert(child.disposed === true);
return assert(!parent.hasOwnProperty(child.id));
},
nonEnumerability: function() {
var key, visibleKeys;
visibleKeys = (function() {
var _results;
_results = [];
for (key in new Component) {
_results.push(key);
}
return _results;
})();
return assertEquals(visibleKeys, []);
}
},
name: "Component",
path: "glass.Component",
namespace: "glass",
require: {
glass: "glass",
"glass.Observable": "Observable"
},
import: {
"glass.Observable": "Observable",
"glass.isString": "isString",
"glass.patch": "patch",
"glass.assert": "assert",
"glass.assertEquals": "assertEquals",
"glass.getId": "getId"
}
}
},
"glass.Container": {
source: "extends: 'Observable'
properties:
watch: ->
unwatch: ->
",
input: "runtime\\glass\\Container.coffee",
content: {
extends: ["glass.Observable"],
properties: {
watch: {
value: function() {},
name: "watch"
},
unwatch: {
value: function() {},
name: "unwatch"
}
},
name: "Container",
path: "glass.Container",
namespace: "glass",
require: {
glass: "glass",
"glass.Observable": "Observable"
},
import: {}
}
},
"glass.Expression._parser": {
source: "{
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e,array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++)
array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
}
start = expression
expression = conditional
conditional = e:or args:(\"?\" b:expression \":\" c:expression {return [b,c];})* {
while (args.length > 0) {
e = expr(\"?:\", [e].concat(args.pop()));
}
return e;
}
or = a:and b:((\"or\") and)* { return joinLeft(a,b); }
and = a:equality b:((\"and\") equality)* { return joinLeft(a,b); }
equality = a:rel b:((\"==\" / \"!=\") rel)* { return joinLeft(a,b); }
rel = a:sum b:((\"<=\" / \">=\" / \"<\" / \">\") sum)* { return joinLeft(a,b); }
sum = a:product b:((\"+\" / \"-\") product)* { return joinLeft(a,b); }
product = a:not b:((\"*\" / \"div\" / \"mod\") not)* { return joinLeft(a,b); }
not = ops:(s op:(\"!\" / \"~\" / \"+\" / \"-\") { return op; })* b:primary { return unaryRight(ops,b); }
primary = s a:(group / literal / path) s { return a; }
group = \"(\" a:expression \")\" { return a; }
literal = s a:(boolean / number / string / array / object) s { return a; }
boolean = a:(\"true\" / \"false\") { return a == \"true\"; }
number = a:([0-9]+ (\".\" [0-9]+)?) { return parseFloat(toString(a)); }
hex = [a-fA-F0-9]
// as per JSON http://www.json.org
string = a:( '\"' (
[\\u0000-\\u0021\\u0023-\\u005c\\u005e-\\uffff] // all unicode chars except \\ and \"
/ (\"\\\\\" (\"\\\"\" / \"\\\\\" / \"\\/\" / \"b\" / \"f\" / \"n\" / \"r\" / \"t\" / (\"u\" hex hex hex hex)))
)* '\"' )
{ return JSON.parse(toString(a)); }
array = \"[\" a:values \"]\" { return expr(\"array\", a); }
values = first:expression? args:(\",\" b:expression {return b;})* {
if (first != \"\") { args.unshift(first); } return args;
}
object = \"{\" a:keyvalues \"}\" { return expr(\"object\", a); }
keyvalue = s a:string s \":\" b:expression { return [a,b]; }
keyvalues = first:keyvalue? rest:(\",\" b:keyvalue {return b;})* {
if (first) { rest.unshift(first); } return rest;
}
ref = a:(\"//\" / \"/\" / \"$\" / \"**\" / \"*\" / \"..\" / \".\") b:slashProperty? {
e = expr(a); if (b) { b.args.unshift(e); e = b; } return e;
}
/ a:id { return expr(\"ref\", [a]); }
id = a:[a-z_]+ b:[a-z_0-9]* { return a.join('') + b.join(''); }
property = \"/\" a:slashProperty { return a; }
/ \"{\" a:expression \"}\" { return expr(\"{}\", [a]); } // locally scoped expression
/ \"[\" a:expression \"]\" { return expr(\"[]\", [a]); } // predicate
slashProperty = a:(id/number/string) { return expr(\"/\", [a]); }
/ a:(\"..\" / \"*\") { return expr(a, []); }
s \"space\" = [ ]* { return ''; }
path = a:root b:step* {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
}
root = a:implicitDotRoot b:dotStep? { return joinPath(a,b); }
/ explicitDotRoot
step = \".\" a:dotStep { return a; }
/ noDotStep
implicitDotRoot = \"/\" { return expr(\"root\"); }
/ \"@\" { return expr(\"this\"); }
/ \".\" a:\".\"+ { return expr(\"ancestor\", [a.length]); }
explicitDotRoot = a:id { return expr(\"ref\", [a]); }
/ \"*\" { return expr(\"values\", []); }
dotStep = a:(id / string / number) { return expr(\"get\", [a]); }
/ \"*\" { return expr(\"values\", []); }
noDotStep = \"{\" a:expression \"}\" { return expr(\"eval\", [a]); }
/ \"[\" a:expression \"]\" { return expr(\"pred\", [a]); }
/ \"(\" a:values \")\" { return expr(\"call\", [a]); }
",
input: "runtime\\glass\\Expression\\_parser.pegjs",
content: {
value: {
parse: function(input, startRule) {
var parseFunctions = {
"conditional": parse_conditional,
"or": parse_or,
"and": parse_and,
"equality": parse_equality,
"rel": parse_rel,
"sum": parse_sum,
"product": parse_product,
"not": parse_not,
"primary": parse_primary,
"group": parse_group,
"literal": parse_literal,
"boolean": parse_boolean,
"number": parse_number,
"hex": parse_hex,
"string": parse_string,
"array": parse_array,
"values": parse_values,
"object": parse_object,
"keyvalue": parse_keyvalue,
"keyvalues": parse_keyvalues,
"ref": parse_ref,
"id": parse_id,
"property": parse_property,
"slashProperty": parse_slashProperty,
"s": parse_s,
"path": parse_path,
"root": parse_root,
"step": parse_step,
"implicitDotRoot": parse_implicitDotRoot,
"explicitDotRoot": parse_explicitDotRoot,
"dotStep": parse_dotStep,
"noDotStep": parse_noDotStep
};
if (startRule !== undefined) {
if (parseFunctions[startRule] === undefined) {
throw new Error("Invalid rule name: " + quote(startRule) + ".");
}
} else {
startRule = "conditional";
}
var pos = 0;
var reportFailures = 0;
var rightmostFailuresPos = 0;
var rightmostFailuresExpected = [];
function padLeft(input, padding, length) {
var result = input;
var padLength = length - input.length;
for (var i = 0; i < padLength; i++) {
result = padding + result;
}
return result;
}
function escape(ch) {
var charCode = ch.charCodeAt(0);
var escapeChar;
var length;
if (charCode <= 0xFF) {
escapeChar = 'x';
length = 2;
} else {
escapeChar = 'u';
length = 4;
}
return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
}
function matchFailed(failure) {
if (pos < rightmostFailuresPos) {
return;
}
if (pos > rightmostFailuresPos) {
rightmostFailuresPos = pos;
rightmostFailuresExpected = [];
}
rightmostFailuresExpected.push(failure);
}
function parse_conditional() {
var result0, result1, result2, result3, result4, result5;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_or();
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, e, args) {
while (args.length > 0) {
e = expr("?:", [e].concat(args.pop()));
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_or() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_and();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_and() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_equality();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_equality() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_rel();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_rel() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_sum();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_sum() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_product();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_product() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_not();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_not() {
var result0, result1, result2;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = [];
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
while (result1 !== null) {
result0.push(result1);
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
}
if (result0 !== null) {
result1 = parse_primary();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, ops, b) {
return unaryRight(ops, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_primary() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_group();
if (result1 === null) {
result1 = parse_literal();
if (result1 === null) {
result1 = parse_path();
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_group() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_literal() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_boolean();
if (result1 === null) {
result1 = parse_number();
if (result1 === null) {
result1 = parse_string();
if (result1 === null) {
result1 = parse_array();
if (result1 === null) {
result1 = parse_object();
}
}
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_boolean() {
var result0;
var pos0;
pos0 = pos;
if (input.substr(pos, 4) === "true") {
result0 = "true";
pos += 4;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"true\"");
}
}
if (result0 === null) {
if (input.substr(pos, 5) === "false") {
result0 = "false";
pos += 5;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"false\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a == "true";
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_number() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
pos2 = pos;
if (input.charCodeAt(pos) === 46) {
result1 = ".";
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result1 !== null) {
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result3 !== null) {
result2 = [];
while (result3 !== null) {
result2.push(result3);
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result2 = null;
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos2;
}
} else {
result1 = null;
pos = pos2;
}
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return parseFloat(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_hex() {
var result0;
if (/^[a-fA-F0-9]/.test(input.charAt(pos))) {
result0 = input.charAt(pos);
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("[a-fA-F0-9]");
}
}
return result0;
}
function parse_string() {
var result0, result1, result2, result3, result4, result5, result6, result7;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 34) {
result0 = "\"";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result0 !== null) {
result1 = [];
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
}
if (result1 !== null) {
if (input.charCodeAt(pos) === 34) {
result2 = "\"";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return JSON.parse(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_array() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("array", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_values() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_conditional();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, args) {
if (first != "") {
args.unshift(first);
}
return args;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_object() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_keyvalues();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("object", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalue() {
var result0, result1, result2, result3, result4;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_string();
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
if (input.charCodeAt(pos) === 58) {
result3 = ":";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result3 !== null) {
result4 = parse_conditional();
if (result4 !== null) {
result0 = [result0, result1, result2, result3, result4];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return [a, b];
})(pos0, result0[1], result0[4]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalues() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_keyvalue();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, rest) {
if (first) {
rest.unshift(first);
}
return rest;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_ref() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.substr(pos, 2) === "//") {
result0 = "//";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"//\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 36) {
result0 = "$";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"$\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "**") {
result0 = "**";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"**\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
}
}
}
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
e = expr(a);
if (b) {
b.args.unshift(e);
e = b;
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_id() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
result1 = [];
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return a.join('') + b.join('');
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_property() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("{}", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("[]", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_slashProperty() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_number();
if (result0 === null) {
result0 = parse_string();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("/", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(a, []);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_s() {
var result0, result1;
var pos0;
reportFailures++;
pos0 = pos;
result0 = [];
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
while (result1 !== null) {
result0.push(result1);
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
}
if (result0 !== null) {
result0 = (function(offset) {
return '';
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
reportFailures--;
if (reportFailures === 0 && result0 === null) {
matchFailed("space");
}
return result0;
}
function parse_path() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_root();
if (result0 !== null) {
result1 = [];
result2 = parse_step();
while (result2 !== null) {
result1.push(result2);
result2 = parse_step();
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_root() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_implicitDotRoot();
if (result0 !== null) {
result1 = parse_dotStep();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinPath(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_explicitDotRoot();
}
return result0;
}
function parse_step() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
result1 = parse_dotStep();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_noDotStep();
}
return result0;
}
function parse_implicitDotRoot() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("root");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 64) {
result0 = "@";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"@\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("this");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result2 !== null) {
result1 = [];
while (result2 !== null) {
result1.push(result2);
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
} else {
result1 = null;
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ancestor", [a.length]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_explicitDotRoot() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_dotStep() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_string();
if (result0 === null) {
result0 = parse_number();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("get", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_noDotStep() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("eval", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("pred", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("call", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function cleanupExpected(expected) {
expected.sort();
var lastExpected = null;
var cleanExpected = [];
for (var i = 0; i < expected.length; i++) {
if (expected[i] !== lastExpected) {
cleanExpected.push(expected[i]);
lastExpected = expected[i];
}
}
return cleanExpected;
}
function computeErrorPosition() {
/*
* The first idea was to use |String.split| to break the input up to the
* error position along newlines and derive the line and column from
* there. However IE's |split| implementation is so broken that it was
* enough to prevent it.
*/
var line = 1;
var column = 1;
var seenCR = false;
for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
var ch = input.charAt(i);
if (ch === "
") {
if (!seenCR) {
line++;
}
column = 1;
seenCR = false;
} else if (ch === "
" || ch === "\u2028" || ch === "\u2029") {
line++;
column = 1;
seenCR = true;
} else {
column++;
seenCR = false;
}
}
return {
line: line,
column: column
};
}
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e, array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++) array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
var result = parseFunctions[startRule]();
/*
* The parser is now in one of the following three states:
*
* 1. The parser successfully parsed the whole input.
*
* - |result !== null|
* - |pos === input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 2. The parser successfully parsed only a part of the input.
*
* - |result !== null|
* - |pos < input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 3. The parser did not successfully parse any part of the input.
*
* - |result === null|
* - |pos === 0|
* - |rightmostFailuresExpected| contains at least one failure
*
* All code following this comment (including called functions) must
* handle these states.
*/
if (result === null || pos !== input.length) {
var offset = Math.max(pos, rightmostFailuresPos);
var found = offset < input.length ? input.charAt(offset) : null;
var errorPosition = computeErrorPosition();
throw new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column);
}
return result;
},
toSource: function() {
return this._source;
},
SyntaxError: function(expected, found, offset, line, column) {
function buildMessage(expected, found) {
var expectedHumanized, foundHumanized;
switch (expected.length) {
case 0:
expectedHumanized = "end of input";
break;
case 1:
expectedHumanized = expected[0];
break;
default:
expectedHumanized = expected.slice(0, expected.length - 1).join(", ") + " or " + expected[expected.length - 1];
}
foundHumanized = found ? quote(found) : "end of input";
return "Expected " + expectedHumanized + " but " + foundHumanized + " found.";
}
this.name = "SyntaxError";
this.expected = expected;
this.found = found;
this.message = buildMessage(expected, found);
this.offset = offset;
this.line = line;
this.column = column;
}
},
name: "_parser",
path: "glass.Expression._parser",
namespace: "glass.Expression",
require: {
"glass.Expression": "Expression"
},
import: {
"glass.values": "values"
}
}
}
}
} | {
options: {
input: {
dir: "runtime",
match: /\.(coffee|pegjs)$/
},
output: {
dir: "www/js"
},
script: {
includes: "www/includes.html",
prefix: "/js/"
},
module: {
main: "glass.js",
prefix: "./www/js/"
},
debug: "buildlog.html",
test: "glass.allTests",
addon: {
pregenerate: {
addUri: function(schema) {
var content, type, typeName, _ref2, _ref3;
_ref2 = schema.types;
for (typeName in _ref2) {
type = _ref2[typeName];
content = type.content;
if (content.extension) {
continue;
}
if ((_ref3 = content.uri) == null) {
content.uri = "global:/" + (content.path.replace(/\./g, '/'));
}
}
return schema;
}
}
},
namespace: ""
},
types: {
String: {
source: "extension: true
properties:
\tstartsWith: (s) -> @slice(0,s.length) is s
\tendsWith: (s) -> @slice(-s.length) is s
\tcontains: (s) -> @indexOf(s) >= 0
\ttoArray: () -> @split ''",
input: "runtime\\String.coffee",
content: {
extension: true,
properties: {
startsWith: {
value: function(s) {
return this.slice(0, s.length) === s;
},
name: "startsWith"
},
endsWith: {
value: function(s) {
return this.slice( - s.length) === s;
},
name: "endsWith"
},
contains: {
value: function(s) {
return this.indexOf(s) >= 0;
},
name: "contains"
},
toArray: {
value: function() {
return this.split('');
},
name: "toArray"
}
},
name: "String",
path: "String",
namespace: "",
require: {},
import: {},
implements: {
String: true
}
}
},
glass: {
source: "require:
\tString: true
# runtime type tests
isFunction: (object) -> object? and typeof object is 'function'
isString: (object) -> object?.constructor is String
isArray: (object) -> Array.isArray object
isBoolean: (object) -> object? and typeof object is 'boolean'
isNumber: (object) -> object? and typeof object is 'number'
isObject: (object) -> typeof object is 'object'
isPlainObject: (object) -> object?.constructor is Object
isPrototype: (object) -> object? and object is object.constructor.prototype
isDate: (object) -> object?.constructor is Date
isPrimitive: (object) -> isString(object) or isBoolean(object) or isNumber(object) or isDate(object)
isPrivate: (property) -> property?[0] is '_'
# generic utility functions
values: (object) -> (value for key, value of object)
# generic patch method, uses patch method built into object if present
patch: (target, pathAndPatch...) ->
patch = JSONMergePatch.create.apply null, pathAndPatch
if isFunction target?.patch
target.patch patch
else
glass.JSONMergePatch.apply target, patch
# testing assertions
_getStackLocationInfo: (e, depth) ->
line = e.stack?.split('
')[depth]
return null unless line?
match = /\\(([\\w\\W]*?):(\\d+):(\\d+)\\)/.exec line
return {
file: match[1]
line: parseInt match[2]
column: parseInt match[3]
}
_throwAssertionFailure: (message) ->
try
throw new Error \"Assertion failed: \" + message
catch e
info = _getStackLocationInfo e, 3
if info?
_dumpFile info.file, info.line - 2, info.line + 2, info.line
throw e
_dumpFile: (file, from=1, to, highlight) ->
fs = require 'fs'
return unless fs?
try
content = fs.readFileSync(file).toString()
catch e
content = \"Source not found: #{e}\"
console.log '------------------------------------------------'
console.log file
console.log '------------------------------------------------'
number = 1
if content?
lines = content.split /
|
/
to ?= lines.length
for line in lines
lineNumber = number++
if lineNumber >= from and lineNumber <= to
num = String lineNumber
while num.length < 3
num += ' '
if lineNumber is highlight
`console.log(\"\\033[91m\" + num + \": \" + line + \"\\033[0m\");`
else
`console.log(num + \": \" + line);`
console.log '------------------------------------------------'
assert: (a) ->
_throwAssertionFailure JSON.stringify(a) unless a
assertTrue: (a) ->
_throwAssertionFailure JSON.stringify(a) + \" != true\" unless a is true
assertEquals: (a, b) ->
if JSON.stringify(a) isnt JSON.stringify(b)
_throwAssertionFailure JSON.stringify(a) + ' != ' + JSON.stringify(b)
# gets a unique string identifier for any object
getId:
do: ->
counter = 0
(a) ->
if a is null
return '__null__'
if a is undefined
return '__undefined__'
if typeof a is 'object' or typeof a is 'function'
return a.id ?= '__' + (counter++) + '__'
# 12 == \"12\" under this technique
return a.toString()
getType: (path) ->
array = if isArray path then path else path.split '.'
value = global
for step in path when value?
value = value[step]
throw new Error \"Type not found: #{path}\" unless isFunction value
value
test:
values: ->
assertEquals values({a:1,b:3,c:2}), [1,3,2]
patch: ->
x = {a:{foo:1,bar:3},b:2}
patch x, 'a', 'foo', 5
assertEquals x.a.foo, 5
",
input: "runtime\\glass.coffee",
content: {
require: {
String: "String"
},
isFunction: function(object) {
return (object != null) && typeof object === 'function';
},
isString: function(object) {
return (object != null ? object.constructor: void 0) === String;
},
isArray: function(object) {
return Array.isArray(object);
},
isBoolean: function(object) {
return (object != null) && typeof object === 'boolean';
},
isNumber: function(object) {
return (object != null) && typeof object === 'number';
},
isObject: function(object) {
return typeof object === 'object';
},
isPlainObject: function(object) {
return (object != null ? object.constructor: void 0) === Object;
},
isPrototype: function(object) {
return (object != null) && object === object.constructor.prototype;
},
isDate: function(object) {
return (object != null ? object.constructor: void 0) === Date;
},
isPrimitive: function(object) {
return isString(object) || isBoolean(object) || isNumber(object) || isDate(object);
},
isPrivate: function(property) {
return (property != null ? property[0] : void 0) === '_';
},
values: function(object) {
var key, value, _results;
_results = [];
for (key in object) {
value = object[key];
_results.push(value);
}
return _results;
},
patch: function() {
var patch, pathAndPatch, target;
target = arguments[0],
pathAndPatch = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
patch = JSONMergePatch.create.apply(null, pathAndPatch);
if (isFunction(target != null ? target.patch: void 0)) {
return target.patch(patch);
} else {
return glass.JSONMergePatch.apply(target, patch);
}
},
assert: function(a) {
if (!a) {
return _throwAssertionFailure(JSON.stringify(a));
}
},
assertTrue: function(a) {
if (a !== true) {
return _throwAssertionFailure(JSON.stringify(a) + " != true");
}
},
assertEquals: function(a, b) {
if (JSON.stringify(a) !== JSON.stringify(b)) {
return _throwAssertionFailure(JSON.stringify(a) + ' != ' + JSON.stringify(b));
}
},
getId: {
do: function() {
var counter;
counter = 0;
return function(a) {
var _ref;
if (a === null) {
return '__null__';
}
if (a === void 0) {
return '__undefined__';
}
if (typeof a === 'object' || typeof a === 'function') {
return (_ref = a.id) != null ? _ref: a.id = '__' + (counter++) + '__';
}
return a.toString();
};
}
},
getType: function(path) {
var array, step, value, _i, _len;
array = isArray(path) ? path: path.split('.');
value = global;
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
if (!isFunction(value)) {
throw new Error("Type not found: " + path);
}
return value;
},
test: {
values: function() {
return assertEquals(values({
a: 1,
b: 3,
c: 2
}), [1, 3, 2]);
},
patch: function() {
var x;
x = {
a: {
foo: 1,
bar: 3
},
b: 2
};
patch(x, 'a', 'foo', 5);
return assertEquals(x.a.foo, 5);
}
},
name: "glass",
path: "glass",
namespace: "",
import: {
"glass.JSONMergePatch": "JSONMergePatch",
"glass.isFunction": "isFunction",
"glass.isString": "isString",
"glass.isArray": "isArray",
"glass.isBoolean": "isBoolean",
"glass.isNumber": "isNumber",
"glass.isDate": "isDate",
"glass.values": "values",
"glass.patch": "patch",
"glass._getStackLocationInfo": "_getStackLocationInfo",
"glass._throwAssertionFailure": "_throwAssertionFailure",
"glass._dumpFile": "_dumpFile",
"glass.assertEquals": "assertEquals"
}
}
},
"glass.Expression": {
source: "constructor: (op, args) ->
@op = op
@args = args if args?
@
properties:
op:
type: 'string'
args:
type: 'array'
test: ->
return
peg = require 'pegjs'
fs = require 'fs'
parserSource = fs.readFileSync 'runtime/glass/Expression/_parser.pegjs', 'utf8'
parser = peg.buildParser parserSource
tests =
\"a.b.c\": {op:\"get\",args:[{op:\"get\",args:[{op:\"ref\",args:[\"a\"]},\"b\"]},\"c\"]}
\"a.1\": {op:\"get\",args:[{op:\"ref\",args:[\"a\"]},1]}
\"true\": true
\"false\": false
\"45.8\": 45.8
\"(45.8)\": 45.8
\"((45.8))\": 45.8
\"alpha\": {op:\"ref\",args:[\"alpha\"]}
\"35 + true * 2\": {op:\"+\", args:[35, {op:\"*\", args:[true,2]}]}
\" 5 * ( 2 + 2 ) \": {op:\"*\", args:[5, {op:\"+\", args:[2,2]}]}
\" ! ! true\": {op:\"!\",args:[{op:\"!\",args:[true]}]}
\"5 + -x\": {op:\"+\",args:[5,{op:\"-\",args:[{op:\"ref\",args:[\"x\"]}]}]}
\"true == 5 >= 2\": {op:\"==\",args:[true,{op:\">=\",args:[5,2]}]}
\"1 or 2 and 3\": {op:\"or\",args:[1,{op:\"and\",args:[2,3]}]}
\"1 ? 2 : 3\": {op:\"?:\",args:[1,2,3]}
\"1 ? 2 : 3 ? 4 : 5\" : {op:\"?:\",args:[1,2,{op:\"?:\",args:[3,4,5]}]}
\"a()(1,2)\" : {op:\"call\",args:[{op:\"call\",args:[{op:\"ref\",args:[\"a\"]},[]]},[1,2]]}
\"@\" : {op:\"this\"}
\"@foo\" : {op:\"get\",args:[{op:\"this\"},\"foo\"]}
'\"hello\"': \"hello\"
'\"\\\\t\\
\\
\\\\b\\\\\\\\foo\\\\\\/\"' : \"\\t
\\b\\\\foo\\/\"
\"[]\": {op:\"array\",args:[]}
\"[1,2]\": {op:\"array\",args:[1,2]}
\"[1+2]\": {op:\"array\",args:[{op:\"+\",args:[1,2]}]}
\"{}\": {op:\"object\",args:[]}
'{\"a\":2}': {op:\"object\",args:[[\"a\",2]]}
'{\"a\":2,\"b\":1+2}': {op:\"object\",args:[[\"a\",2],[\"b\",{op:\"+\",args:[1,2]}]]}
'@\"alpha\"': {op:\"get\",args:[{op:\"this\"},\"alpha\"]}
'*': {op:\"values\",args:[]}
'*.*': {op:\"values\",args:[{op:\"values\",args:[]}]}
\"foo.*\": {op:\"values\",args:[{op:\"ref\",args:[\"foo\"]}]}
\"..\": {op:\"ancestor\",args:[1]}
\"...\": {op:\"ancestor\",args:[2]}
\"@*{1+2}\": {op:\"eval\",args:[{op:\"values\",args:[{op:\"this\"}]},{op:\"+\",args:[1,2]}]}
\"/\": {op:\"root\"}
\"/foo\": {op:\"get\",args:[{op:\"root\"},\"foo\"]}
\"/*\": {op:\"values\",args:[{op:\"root\"}]}
for text, expected of tests
result = parser.parse text
if JSON.stringify(result) is JSON.stringify(expected)
console.log 'Pass: ' + text
else
console.log text, JSON.stringify result
return
",
input: "runtime\\glass\\Expression.coffee",
content: {
constructor: function(op, args) {
this.op = op;
if (args != null) {
this.args = args;
}
return this;
},
properties: {
op: {
type: "string",
name: "op",
writable: true
},
args: {
type: "array",
name: "args",
writable: true
}
},
test: function() {
var expected, fs, parser, parserSource, peg, result, tests, text;
return;
peg = require('pegjs');
fs = require('fs');
parserSource = fs.readFileSync('runtime/glass/Expression/_parser.pegjs', 'utf8');
parser = peg.buildParser(parserSource);
tests = {
"a.b.c": {
op: "get",
args: [{
op: "get",
args: [{
op: "ref",
args: ["a"]
},
"b"]
},
"c"]
},
"a.1": {
op: "get",
args: [{
op: "ref",
args: ["a"]
},
1]
},
"true": true,
"false": false,
"45.8": 45.8,
"(45.8)": 45.8,
"((45.8))": 45.8,
"alpha": {
op: "ref",
args: ["alpha"]
},
"35 + true * 2": {
op: "+",
args: [35, {
op: "*",
args: [true, 2]
}]
},
" 5 * ( 2 + 2 ) ": {
op: "*",
args: [5, {
op: "+",
args: [2, 2]
}]
},
" ! ! true": {
op: "!",
args: [{
op: "!",
args: [true]
}]
},
"5 + -x": {
op: "+",
args: [5, {
op: "-",
args: [{
op: "ref",
args: ["x"]
}]
}]
},
"true == 5 >= 2": {
op: "==",
args: [true, {
op: ">=",
args: [5, 2]
}]
},
"1 or 2 and 3": {
op: "or",
args: [1, {
op: "and",
args: [2, 3]
}]
},
"1 ? 2 : 3": {
op: "?:",
args: [1, 2, 3]
},
"1 ? 2 : 3 ? 4 : 5": {
op: "?:",
args: [1, 2, {
op: "?:",
args: [3, 4, 5]
}]
},
"a()(1,2)": {
op: "call",
args: [{
op: "call",
args: [{
op: "ref",
args: ["a"]
},
[]]
},
[1, 2]]
},
"@": {
op: "this"
},
"@foo": {
op: "get",
args: [{
op: "this"
},
"foo"]
},
'"hello"': "hello",
'"\\t
\\b\\\\foo\\\/"': "\t
\b\\foo\/",
"[]": {
op: "array",
args: []
},
"[1,2]": {
op: "array",
args: [1, 2]
},
"[1+2]": {
op: "array",
args: [{
op: "+",
args: [1, 2]
}]
},
"{}": {
op: "object",
args: []
},
'{"a":2}': {
op: "object",
args: [["a", 2]]
},
'{"a":2,"b":1+2}': {
op: "object",
args: [["a", 2], ["b", {
op: "+",
args: [1, 2]
}]]
},
'@"alpha"': {
op: "get",
args: [{
op: "this"
},
"alpha"]
},
'*': {
op: "values",
args: []
},
'*.*': {
op: "values",
args: [{
op: "values",
args: []
}]
},
"foo.*": {
op: "values",
args: [{
op: "ref",
args: ["foo"]
}]
},
"..": {
op: "ancestor",
args: [1]
},
"...": {
op: "ancestor",
args: [2]
},
"@*{1+2}": {
op: "eval",
args: [{
op: "values",
args: [{
op: "this"
}]
},
{
op: "+",
args: [1, 2]
}]
},
"/": {
op: "root"
},
"/foo": {
op: "get",
args: [{
op: "root"
},
"foo"]
},
"/*": {
op: "values",
args: [{
op: "root"
}]
}
};
for (text in tests) {
expected = tests[text];
result = parser.parse(text);
if (JSON.stringify(result) === JSON.stringify(expected)) {
console.log('Pass: ' + text);
} else {
console.log(text, JSON.stringify(result));
}
}
},
name: "Expression",
path: "glass.Expression",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.Expression._parser": "_parser",
"glass.values": "values"
},
implements: {
"glass.Expression": true
}
}
},
"glass.JSONMergePatch": {
source: "
# applies a patch to the target object and returns the resulting target
apply: (target, patch) ->
if target? and target isnt patch and isPlainObject(patch) and not isPrimitive(target)
for key, value of patch
if value is undefined
delete target[key]
else
target[key] = apply target[key], patch[key]
return target
else
return patch
# (path1, path2, path3.., patch) ->
create: ->
if arguments.length is 1
return arguments[0]
result = {}
current = result
for arg, i in arguments when i + 1 < arguments.length
last = i + 2 is arguments.length
current = current[arg] = if last then arguments[arguments.length-1] else {}
result
test: ->
assertEquals {a:{b:12}}, create 'a', 'b', 12
assertEquals {a:3}, apply({a:1,b:2}, {a:3,b:undefined})
",
input: "runtime\\glass\\JSONMergePatch.coffee",
content: {
apply: function(target, patch) {
var key, value;
if ((target != null) && target !== patch && isPlainObject(patch) && !isPrimitive(target)) {
for (key in patch) {
value = patch[key];
if (value === void 0) {
delete target[key];
} else {
target[key] = apply(target[key], patch[key]);
}
}
return target;
} else {
return patch;
}
},
create: function() {
var arg, current, i, last, result, _i, _len;
if (arguments.length === 1) {
return arguments[0];
}
result = {};
current = result;
for (i = _i = 0, _len = arguments.length; _i < _len; i = ++_i) {
arg = arguments[i];
if (! (i + 1 < arguments.length)) {
continue;
}
last = i + 2 === arguments.length;
current = current[arg] = last ? arguments[arguments.length - 1] : {};
}
return result;
},
test: function() {
assertEquals({
a: {
b: 12
}
},
create('a', 'b', 12));
return assertEquals({
a: 3
},
apply({
a: 1,
b: 2
},
{
a: 3,
b: void 0
}));
},
name: "JSONMergePatch",
path: "glass.JSONMergePatch",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONMergePatch.apply": "apply",
"glass.JSONMergePatch.create": "create",
"glass.isPlainObject": "isPlainObject",
"glass.isPrimitive": "isPrimitive",
"glass.patch": "patch",
"glass.assertEquals": "assertEquals"
}
}
},
"glass.JSONPointer": {
source: "# json pointer implementation as per
# http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-05
_decodeStep: (step) -> step.replace(/~1/g, '/').replace(/~0/g, '~')
_getLastStep: (pointer) ->
_decodeStep pointer.substring(pointer.lastIndexOf('/') + 1)
_getParent: (pointer) ->
if not pointer?.length
null
else
pointer.substring(0, pointer.lastIndexOf('/'))
toArray: (pointer) ->
for step in pointer.substring(1).split('/')
_decodeStep step
get: (doc, pointer) ->
value = doc
if pointer.length
path = toArray pointer
for step in path when value?
value = value[step]
value
set: (doc, pointer, value) ->
parentPointer = _getParent pointer
if parentPointer?
parent = get doc, parentPointer
lastStep = _getLastStep pointer
parent[lastStep] = value
value
test: ->
assertEquals _getParent(\"/a/b/c\"), \"/a/b\"
assertEquals _getParent(\"/a\"), \"\"
assertEquals _getParent(\"\"), null
assertEquals _getLastStep(\"/a/b/c\"), \"c\"
assertEquals _getLastStep(\"/a~0~1\"), \"a~/\"
assertEquals _getLastStep(\"\"), \"\"
# tests as per spec
doc = {
\"foo\": [\"bar\", \"baz\"],
\"\": 0,
\"a/b\": 1,
\"c%d\": 2,
\"e^f\": 3,
\"g|h\": 4,
\"i\\\\j\": 5,
\"k\\\"l\": 6,
\" \": 7,
\"m~n\": 8
}
assertEquals get(doc, \"\"), doc
assertEquals get(doc, \"/foo\"), [\"bar\", \"baz\"]
assertEquals get(doc, \"/foo/0\"), \"bar\"
assertEquals get(doc, \"/\"), 0
assertEquals get(doc, \"/a~1b\"), 1
assertEquals get(doc, \"/c%d\"), 2
assertEquals get(doc, \"/e^f\"), 3
assertEquals get(doc, \"/g|h\"), 4
assertEquals get(doc, \"/i\\\\j\"), 5
assertEquals get(doc, \"/k\\\"l\"), 6
assertEquals get(doc, \"/ \"), 7
assertEquals get(doc, \"/m~0n\"), 8
# now test set
assertEquals set(doc, \"/\", 10), 10
assertEquals doc[\"\"], 10
assertEquals set(doc, \"/foo/0\", 10), 10
assertEquals doc.foo[0], 10",
input: "runtime\\glass\\JSONPointer.coffee",
content: {
toArray: function(pointer) {
var step, _i, _len, _ref, _results;
_ref = pointer.substring(1).split('/');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
step = _ref[_i];
_results.push(_decodeStep(step));
}
return _results;
},
get: function(doc, pointer) {
var path, step, value, _i, _len;
value = doc;
if (pointer.length) {
path = toArray(pointer);
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
}
return value;
},
set: function(doc, pointer, value) {
var lastStep, parent, parentPointer;
parentPointer = _getParent(pointer);
if (parentPointer != null) {
parent = get(doc, parentPointer);
lastStep = _getLastStep(pointer);
parent[lastStep] = value;
}
return value;
},
test: function() {
var doc;
assertEquals(_getParent("/a/b/c"), "/a/b");
assertEquals(_getParent("/a"), "");
assertEquals(_getParent(""), null);
assertEquals(_getLastStep("/a/b/c"), "c");
assertEquals(_getLastStep("/a~0~1"), "a~/");
assertEquals(_getLastStep(""), "");
doc = {
"foo": ["bar", "baz"],
"": 0,
"a/b": 1,
"c%d": 2,
"e^f": 3,
"g|h": 4,
"i\\j": 5,
"k\"l": 6,
" ": 7,
"m~n": 8
};
assertEquals(get(doc, ""), doc);
assertEquals(get(doc, "/foo"), ["bar", "baz"]);
assertEquals(get(doc, "/foo/0"), "bar");
assertEquals(get(doc, "/"), 0);
assertEquals(get(doc, "/a~1b"), 1);
assertEquals(get(doc, "/c%d"), 2);
assertEquals(get(doc, "/e^f"), 3);
assertEquals(get(doc, "/g|h"), 4);
assertEquals(get(doc, "/i\\j"), 5);
assertEquals(get(doc, "/k\"l"), 6);
assertEquals(get(doc, "/ "), 7);
assertEquals(get(doc, "/m~0n"), 8);
assertEquals(set(doc, "/", 10), 10);
assertEquals(doc[""], 10);
assertEquals(set(doc, "/foo/0", 10), 10);
return assertEquals(doc.foo[0], 10);
},
name: "JSONPointer",
path: "glass.JSONPointer",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONPointer._decodeStep": "_decodeStep",
"glass.JSONPointer._getLastStep": "_getLastStep",
"glass.JSONPointer._getParent": "_getParent",
"glass.JSONPointer.toArray": "toArray",
"glass.JSONPointer.get": "get",
"glass.JSONPointer.set": "set",
"glass.assertEquals": "assertEquals"
}
}
},
"glass.Observable": {
source: "properties:
is: (type) -> @constructor.implements[type.path ? type] is true
watchers:
serializable: false
watch: (property, watcher) ->
if isFunction property
watcher = property
property = ''
id = getId watcher
@patch 'watchers', property, id, watcher
# returns a function which will remove the watch
=> @patch 'watchers', property, getId(watcher), undefined
patch: (change) ->
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
try
JSONMergePatch.apply this, change
catch e
console.log e
finally
@notify change
return
notify: (change) ->
if @watchers?
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
for property, watchers of @watchers
if property.length is 0 or change.hasOwnProperty property
changeArg = if property.length is 0 then change else change[property]
for id, watcher of watchers
watcher this, changeArg
return
toJSON: ->
values =
class: @constructor.path
# serialize statically defined properties
for name, property of @constructor.properties
value = @[name]
if property.serializable isnt false and not isFunction(value)
values[name] = value
# serialize custom properties if allowed by schema
if @constructor.additionalProperties isnt false
for own name, value of @ when not isPrivate name
values[name] = value
values
toString: -> @toJSON()
test:
toJSON: ->
# I need this test later
# on a class that actually has serializable properties
a = new Observable
a.x = 12
a.y = ->
a.z = true
assertEquals a, {class:'glass.Observable', x:12,z:true}
watchAll: ->
# we should actually be able to watch ourselves get added to watchers
# this is very meta.
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch watcher
# now make sure we were called with our own watcher
assert watchArgs[0] is a
assert watchArgs[1]?.watchers?[\"\"]?
# reset watchArgs, and watch something else
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assertEquals a.a, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {a:{b:3}}
# now unwatch
unwatch()
# make sure universal watcher is now empty
assertEquals a.watchers[\"\"], {}
# now reset and do a new event, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
watchProperty: ->
# watch a property
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch \"foo\", watcher
# now make sure we were not called
assert watchArgs.length is 0
# reset watchArgs, and watch something else
a.patch \"foo\", \"b\", 3
assertEquals a.foo, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {b:3}
# now reset and do a different property, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
# now unwatch
unwatch()
# make sure we no longer see foo
watchArgs.length = 0
a.patch \"foo\", \"b\", 4
assert watchArgs.length is 0
",
input: "runtime\\glass\\Observable.coffee",
content: {
properties: {
is: {
value: function(type) {
var _ref;
return this.constructor["implements"][(_ref = type.path) != null ? _ref: type] === true;
},
name: "is"
},
watchers: {
serializable: false,
name: "watchers",
writable: true
},
watch: {
value: function(property, watcher) {
var id, _this = this;
if (isFunction(property)) {
watcher = property;
property = '';
}
id = getId(watcher);
this.patch('watchers', property, id, watcher);
return function() {
return _this.patch('watchers', property, getId(watcher), void 0);
};
},
name: "watch"
},
patch: {
value: function(change) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
try {
JSONMergePatch.apply(this, change);
} catch(e) {
console.log(e);
} finally {
this.notify(change);
}
},
name: "patch"
},
notify: {
value: function(change) {
var changeArg, id, property, watcher, watchers, _ref;
if (this.watchers != null) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
_ref = this.watchers;
for (property in _ref) {
watchers = _ref[property];
if (property.length === 0 || change.hasOwnProperty(property)) {
changeArg = property.length === 0 ? change: change[property];
for (id in watchers) {
watcher = watchers[id];
watcher(this, changeArg);
}
}
}
}
},
name: "notify"
},
toJSON: {
value: function() {
var name, property, value, values, _ref;
values = {
"class": this.constructor.path
};
_ref = this.constructor.properties;
for (name in _ref) {
property = _ref[name];
value = this[name];
if (property.serializable !== false && !isFunction(value)) {
values[name] = value;
}
}
if (this.constructor.additionalProperties !== false) {
for (name in this) {
if (!__hasProp.call(this, name)) continue;
value = this[name];
if (!isPrivate(name)) {
values[name] = value;
}
}
}
return values;
},
name: "toJSON"
},
toString: {
value: function() {
return this.toJSON();
},
name: "toString"
}
},
test: {
toJSON: function() {
var a;
a = new Observable;
a.x = 12;
a.y = function() {};
a.z = true;
return assertEquals(a, {
"class": 'glass.Observable',
x: 12,
z: true
});
},
watchAll: function() {
var a, unwatch, watchArgs, watcher, _ref, _ref1;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch(watcher);
assert(watchArgs[0] === a);
assert(((_ref = watchArgs[1]) != null ? (_ref1 = _ref.watchers) != null ? _ref1[""] : void 0 : void 0) != null);
watchArgs.length = 0;
a.patch("a", "b", 3);
assertEquals(a.a, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
a: {
b: 3
}
});
unwatch();
assertEquals(a.watchers[""], {});
watchArgs.length = 0;
a.patch("a", "b", 3);
return assert(watchArgs.length === 0);
},
watchProperty: function() {
var a, unwatch, watchArgs, watcher;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch("foo", watcher);
assert(watchArgs.length === 0);
a.patch("foo", "b", 3);
assertEquals(a.foo, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
b: 3
});
watchArgs.length = 0;
a.patch("a", "b", 3);
assert(watchArgs.length === 0);
unwatch();
watchArgs.length = 0;
a.patch("foo", "b", 4);
return assert(watchArgs.length === 0);
}
},
name: "Observable",
path: "glass.Observable",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONMergePatch": "JSONMergePatch",
"glass.isFunction": "isFunction",
"glass.isPrivate": "isPrivate",
"glass.values": "values",
"glass.patch": "patch",
"glass.assert": "assert",
"glass.assertEquals": "assertEquals",
"glass.getId": "getId"
},
implements: {
"glass.Observable": true
}
}
},
"glass.Component": {
source: "extends: 'Observable'
constructor: (properties) ->
@patch properties
# now site ourselves on our parent
if @parent
id = getId @
patch @parent, id, @
@
properties:
id:
description: 'string which uniquely identifies this component within its parent'
type: 'string'
parent:
description: 'the object that contains this component'
serializable: false
type: 'object'
disposed: false
dispose: -> @patch 'disposed', true
notify: (change) ->
Observable.prototype.notify.apply this, arguments
if change?.disposed
# dispose of any disposable children
for id, child of @ when child?.parent is @
child.dispose?()
# remove self from parent
if @id and @parent
patch @parent, @id, undefined
return
test:
lifecycle: ->
parent = new Component
assert not parent.id?
assert not parent.parent?
child = new Component parent:parent
# id should be automatically assigned
assert isString child.id
assert parent is child.parent
assert parent[child.id] is child
assert parent.hasOwnProperty child.id
parent.dispose()
assert child.disposed is true
assert not parent.hasOwnProperty child.id
nonEnumerability: ->
visibleKeys = (key for key of new Component)
assertEquals visibleKeys, []",
input: "runtime\\glass\\Component.coffee",
content: {
extends: ["glass.Observable"],
constructor: function(properties) {
var id;
this.patch(properties);
if (this.parent) {
id = getId(this);
patch(this.parent, id, this);
}
return this;
},
properties: {
id: {
description: "string which uniquely identifies this component within its parent",
type: "string",
name: "id",
writable: true
},
parent: {
description: "the object that contains this component",
serializable: false,
type: "object",
name: "parent",
writable: true
},
disposed: {
value: false,
name: "disposed",
writable: true
},
dispose: {
value: function() {
return this.patch('disposed', true);
},
name: "dispose"
},
notify: {
value: function(change) {
var child, id;
Observable.prototype.notify.apply(this, arguments);
if (change != null ? change.disposed: void 0) {
for (id in this) {
child = this[id];
if ((child != null ? child.parent: void 0) === this) {
if (typeof child.dispose === "function") {
child.dispose();
}
}
}
if (this.id && this.parent) {
patch(this.parent, this.id, void 0);
}
}
},
name: "notify"
}
},
test: {
lifecycle: function() {
var child, parent;
parent = new Component;
assert(!(parent.id != null));
assert(!(parent.parent != null));
child = new Component({
parent: parent
});
assert(isString(child.id));
assert(parent === child.parent);
assert(parent[child.id] === child);
assert(parent.hasOwnProperty(child.id));
parent.dispose();
assert(child.disposed === true);
return assert(!parent.hasOwnProperty(child.id));
},
nonEnumerability: function() {
var key, visibleKeys;
visibleKeys = (function() {
var _results;
_results = [];
for (key in new Component) {
_results.push(key);
}
return _results;
})();
return assertEquals(visibleKeys, []);
}
},
name: "Component",
path: "glass.Component",
namespace: "glass",
require: {
glass: "glass",
"glass.Observable": "Observable"
},
import: {
"glass.Observable": "Observable",
"glass.isString": "isString",
"glass.patch": "patch",
"glass.assert": "assert",
"glass.assertEquals": "assertEquals",
"glass.getId": "getId"
},
implements: {
"glass.Component": true,
"glass.Observable": true
}
}
},
"glass.Container": {
source: "extends: 'Observable'
properties:
watch: ->
unwatch: ->
",
input: "runtime\\glass\\Container.coffee",
content: {
extends: ["glass.Observable"],
properties: {
watch: {
value: function() {},
name: "watch"
},
unwatch: {
value: function() {},
name: "unwatch"
}
},
name: "Container",
path: "glass.Container",
namespace: "glass",
require: {
glass: "glass",
"glass.Observable": "Observable"
},
import: {},
implements: {
"glass.Container": true,
"glass.Observable": true
}
}
},
"glass.Expression._parser": {
source: "{
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e,array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++)
array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
}
start = expression
expression = conditional
conditional = e:or args:(\"?\" b:expression \":\" c:expression {return [b,c];})* {
while (args.length > 0) {
e = expr(\"?:\", [e].concat(args.pop()));
}
return e;
}
or = a:and b:((\"or\") and)* { return joinLeft(a,b); }
and = a:equality b:((\"and\") equality)* { return joinLeft(a,b); }
equality = a:rel b:((\"==\" / \"!=\") rel)* { return joinLeft(a,b); }
rel = a:sum b:((\"<=\" / \">=\" / \"<\" / \">\") sum)* { return joinLeft(a,b); }
sum = a:product b:((\"+\" / \"-\") product)* { return joinLeft(a,b); }
product = a:not b:((\"*\" / \"div\" / \"mod\") not)* { return joinLeft(a,b); }
not = ops:(s op:(\"!\" / \"~\" / \"+\" / \"-\") { return op; })* b:primary { return unaryRight(ops,b); }
primary = s a:(group / literal / path) s { return a; }
group = \"(\" a:expression \")\" { return a; }
literal = s a:(boolean / number / string / array / object) s { return a; }
boolean = a:(\"true\" / \"false\") { return a == \"true\"; }
number = a:([0-9]+ (\".\" [0-9]+)?) { return parseFloat(toString(a)); }
hex = [a-fA-F0-9]
// as per JSON http://www.json.org
string = a:( '\"' (
[\\u0000-\\u0021\\u0023-\\u005c\\u005e-\\uffff] // all unicode chars except \\ and \"
/ (\"\\\\\" (\"\\\"\" / \"\\\\\" / \"\\/\" / \"b\" / \"f\" / \"n\" / \"r\" / \"t\" / (\"u\" hex hex hex hex)))
)* '\"' )
{ return JSON.parse(toString(a)); }
array = \"[\" a:values \"]\" { return expr(\"array\", a); }
values = first:expression? args:(\",\" b:expression {return b;})* {
if (first != \"\") { args.unshift(first); } return args;
}
object = \"{\" a:keyvalues \"}\" { return expr(\"object\", a); }
keyvalue = s a:string s \":\" b:expression { return [a,b]; }
keyvalues = first:keyvalue? rest:(\",\" b:keyvalue {return b;})* {
if (first) { rest.unshift(first); } return rest;
}
ref = a:(\"//\" / \"/\" / \"$\" / \"**\" / \"*\" / \"..\" / \".\") b:slashProperty? {
e = expr(a); if (b) { b.args.unshift(e); e = b; } return e;
}
/ a:id { return expr(\"ref\", [a]); }
id = a:[a-z_]+ b:[a-z_0-9]* { return a.join('') + b.join(''); }
property = \"/\" a:slashProperty { return a; }
/ \"{\" a:expression \"}\" { return expr(\"{}\", [a]); } // locally scoped expression
/ \"[\" a:expression \"]\" { return expr(\"[]\", [a]); } // predicate
slashProperty = a:(id/number/string) { return expr(\"/\", [a]); }
/ a:(\"..\" / \"*\") { return expr(a, []); }
s \"space\" = [ ]* { return ''; }
path = a:root b:step* {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
}
root = a:implicitDotRoot b:dotStep? { return joinPath(a,b); }
/ explicitDotRoot
step = \".\" a:dotStep { return a; }
/ noDotStep
implicitDotRoot = \"/\" { return expr(\"root\"); }
/ \"@\" { return expr(\"this\"); }
/ \".\" a:\".\"+ { return expr(\"ancestor\", [a.length]); }
explicitDotRoot = a:id { return expr(\"ref\", [a]); }
/ \"*\" { return expr(\"values\", []); }
dotStep = a:(id / string / number) { return expr(\"get\", [a]); }
/ \"*\" { return expr(\"values\", []); }
noDotStep = \"{\" a:expression \"}\" { return expr(\"eval\", [a]); }
/ \"[\" a:expression \"]\" { return expr(\"pred\", [a]); }
/ \"(\" a:values \")\" { return expr(\"call\", [a]); }
",
input: "runtime\\glass\\Expression\\_parser.pegjs",
content: {
value: {
parse: function(input, startRule) {
var parseFunctions = {
"conditional": parse_conditional,
"or": parse_or,
"and": parse_and,
"equality": parse_equality,
"rel": parse_rel,
"sum": parse_sum,
"product": parse_product,
"not": parse_not,
"primary": parse_primary,
"group": parse_group,
"literal": parse_literal,
"boolean": parse_boolean,
"number": parse_number,
"hex": parse_hex,
"string": parse_string,
"array": parse_array,
"values": parse_values,
"object": parse_object,
"keyvalue": parse_keyvalue,
"keyvalues": parse_keyvalues,
"ref": parse_ref,
"id": parse_id,
"property": parse_property,
"slashProperty": parse_slashProperty,
"s": parse_s,
"path": parse_path,
"root": parse_root,
"step": parse_step,
"implicitDotRoot": parse_implicitDotRoot,
"explicitDotRoot": parse_explicitDotRoot,
"dotStep": parse_dotStep,
"noDotStep": parse_noDotStep
};
if (startRule !== undefined) {
if (parseFunctions[startRule] === undefined) {
throw new Error("Invalid rule name: " + quote(startRule) + ".");
}
} else {
startRule = "conditional";
}
var pos = 0;
var reportFailures = 0;
var rightmostFailuresPos = 0;
var rightmostFailuresExpected = [];
function padLeft(input, padding, length) {
var result = input;
var padLength = length - input.length;
for (var i = 0; i < padLength; i++) {
result = padding + result;
}
return result;
}
function escape(ch) {
var charCode = ch.charCodeAt(0);
var escapeChar;
var length;
if (charCode <= 0xFF) {
escapeChar = 'x';
length = 2;
} else {
escapeChar = 'u';
length = 4;
}
return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
}
function matchFailed(failure) {
if (pos < rightmostFailuresPos) {
return;
}
if (pos > rightmostFailuresPos) {
rightmostFailuresPos = pos;
rightmostFailuresExpected = [];
}
rightmostFailuresExpected.push(failure);
}
function parse_conditional() {
var result0, result1, result2, result3, result4, result5;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_or();
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, e, args) {
while (args.length > 0) {
e = expr("?:", [e].concat(args.pop()));
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_or() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_and();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_and() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_equality();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_equality() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_rel();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_rel() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_sum();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_sum() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_product();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_product() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_not();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_not() {
var result0, result1, result2;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = [];
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
while (result1 !== null) {
result0.push(result1);
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
}
if (result0 !== null) {
result1 = parse_primary();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, ops, b) {
return unaryRight(ops, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_primary() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_group();
if (result1 === null) {
result1 = parse_literal();
if (result1 === null) {
result1 = parse_path();
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_group() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_literal() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_boolean();
if (result1 === null) {
result1 = parse_number();
if (result1 === null) {
result1 = parse_string();
if (result1 === null) {
result1 = parse_array();
if (result1 === null) {
result1 = parse_object();
}
}
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_boolean() {
var result0;
var pos0;
pos0 = pos;
if (input.substr(pos, 4) === "true") {
result0 = "true";
pos += 4;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"true\"");
}
}
if (result0 === null) {
if (input.substr(pos, 5) === "false") {
result0 = "false";
pos += 5;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"false\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a == "true";
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_number() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
pos2 = pos;
if (input.charCodeAt(pos) === 46) {
result1 = ".";
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result1 !== null) {
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result3 !== null) {
result2 = [];
while (result3 !== null) {
result2.push(result3);
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result2 = null;
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos2;
}
} else {
result1 = null;
pos = pos2;
}
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return parseFloat(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_hex() {
var result0;
if (/^[a-fA-F0-9]/.test(input.charAt(pos))) {
result0 = input.charAt(pos);
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("[a-fA-F0-9]");
}
}
return result0;
}
function parse_string() {
var result0, result1, result2, result3, result4, result5, result6, result7;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 34) {
result0 = "\"";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result0 !== null) {
result1 = [];
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
}
if (result1 !== null) {
if (input.charCodeAt(pos) === 34) {
result2 = "\"";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return JSON.parse(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_array() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("array", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_values() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_conditional();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, args) {
if (first != "") {
args.unshift(first);
}
return args;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_object() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_keyvalues();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("object", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalue() {
var result0, result1, result2, result3, result4;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_string();
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
if (input.charCodeAt(pos) === 58) {
result3 = ":";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result3 !== null) {
result4 = parse_conditional();
if (result4 !== null) {
result0 = [result0, result1, result2, result3, result4];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return [a, b];
})(pos0, result0[1], result0[4]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalues() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_keyvalue();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, rest) {
if (first) {
rest.unshift(first);
}
return rest;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_ref() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.substr(pos, 2) === "//") {
result0 = "//";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"//\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 36) {
result0 = "$";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"$\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "**") {
result0 = "**";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"**\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
}
}
}
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
e = expr(a);
if (b) {
b.args.unshift(e);
e = b;
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_id() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
result1 = [];
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return a.join('') + b.join('');
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_property() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("{}", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("[]", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_slashProperty() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_number();
if (result0 === null) {
result0 = parse_string();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("/", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(a, []);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_s() {
var result0, result1;
var pos0;
reportFailures++;
pos0 = pos;
result0 = [];
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
while (result1 !== null) {
result0.push(result1);
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
}
if (result0 !== null) {
result0 = (function(offset) {
return '';
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
reportFailures--;
if (reportFailures === 0 && result0 === null) {
matchFailed("space");
}
return result0;
}
function parse_path() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_root();
if (result0 !== null) {
result1 = [];
result2 = parse_step();
while (result2 !== null) {
result1.push(result2);
result2 = parse_step();
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_root() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_implicitDotRoot();
if (result0 !== null) {
result1 = parse_dotStep();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinPath(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_explicitDotRoot();
}
return result0;
}
function parse_step() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
result1 = parse_dotStep();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_noDotStep();
}
return result0;
}
function parse_implicitDotRoot() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("root");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 64) {
result0 = "@";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"@\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("this");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result2 !== null) {
result1 = [];
while (result2 !== null) {
result1.push(result2);
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
} else {
result1 = null;
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ancestor", [a.length]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_explicitDotRoot() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_dotStep() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_string();
if (result0 === null) {
result0 = parse_number();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("get", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_noDotStep() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("eval", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("pred", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("call", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function cleanupExpected(expected) {
expected.sort();
var lastExpected = null;
var cleanExpected = [];
for (var i = 0; i < expected.length; i++) {
if (expected[i] !== lastExpected) {
cleanExpected.push(expected[i]);
lastExpected = expected[i];
}
}
return cleanExpected;
}
function computeErrorPosition() {
/*
* The first idea was to use |String.split| to break the input up to the
* error position along newlines and derive the line and column from
* there. However IE's |split| implementation is so broken that it was
* enough to prevent it.
*/
var line = 1;
var column = 1;
var seenCR = false;
for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
var ch = input.charAt(i);
if (ch === "
") {
if (!seenCR) {
line++;
}
column = 1;
seenCR = false;
} else if (ch === "
" || ch === "\u2028" || ch === "\u2029") {
line++;
column = 1;
seenCR = true;
} else {
column++;
seenCR = false;
}
}
return {
line: line,
column: column
};
}
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e, array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++) array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
var result = parseFunctions[startRule]();
/*
* The parser is now in one of the following three states:
*
* 1. The parser successfully parsed the whole input.
*
* - |result !== null|
* - |pos === input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 2. The parser successfully parsed only a part of the input.
*
* - |result !== null|
* - |pos < input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 3. The parser did not successfully parse any part of the input.
*
* - |result === null|
* - |pos === 0|
* - |rightmostFailuresExpected| contains at least one failure
*
* All code following this comment (including called functions) must
* handle these states.
*/
if (result === null || pos !== input.length) {
var offset = Math.max(pos, rightmostFailuresPos);
var found = offset < input.length ? input.charAt(offset) : null;
var errorPosition = computeErrorPosition();
throw new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column);
}
return result;
},
toSource: function() {
return this._source;
},
SyntaxError: function(expected, found, offset, line, column) {
function buildMessage(expected, found) {
var expectedHumanized, foundHumanized;
switch (expected.length) {
case 0:
expectedHumanized = "end of input";
break;
case 1:
expectedHumanized = expected[0];
break;
default:
expectedHumanized = expected.slice(0, expected.length - 1).join(", ") + " or " + expected[expected.length - 1];
}
foundHumanized = found ? quote(found) : "end of input";
return "Expected " + expectedHumanized + " but " + foundHumanized + " found.";
}
this.name = "SyntaxError";
this.expected = expected;
this.found = found;
this.message = buildMessage(expected, found);
this.offset = offset;
this.line = line;
this.column = column;
}
},
name: "_parser",
path: "glass.Expression._parser",
namespace: "glass.Expression",
require: {
"glass.Expression": "Expression"
},
import: {
"glass.values": "values"
}
}
}
}
} | {
options: {
input: {
dir: "runtime",
match: /\.(coffee|pegjs)$/
},
output: {
dir: "www/js"
},
script: {
includes: "www/includes.html",
prefix: "/js/"
},
module: {
main: "glass.js",
prefix: "./www/js/"
},
debug: "buildlog.html",
test: "glass.allTests",
addon: {
pregenerate: {
addUri: function(schema) {
var content, type, typeName, _ref2, _ref3;
_ref2 = schema.types;
for (typeName in _ref2) {
type = _ref2[typeName];
content = type.content;
if (content.extension) {
continue;
}
if ((_ref3 = content.uri) == null) {
content.uri = "global:/" + (content.path.replace(/\./g, '/'));
}
}
return schema;
}
}
},
namespace: ""
},
types: {
String: {
source: "extension: true
properties:
\tstartsWith: (s) -> @slice(0,s.length) is s
\tendsWith: (s) -> @slice(-s.length) is s
\tcontains: (s) -> @indexOf(s) >= 0
\ttoArray: () -> @split ''",
input: "runtime\\String.coffee",
content: {
extension: true,
properties: {
startsWith: {
value: function(s) {
return this.slice(0, s.length) === s;
},
name: "startsWith"
},
endsWith: {
value: function(s) {
return this.slice( - s.length) === s;
},
name: "endsWith"
},
contains: {
value: function(s) {
return this.indexOf(s) >= 0;
},
name: "contains"
},
toArray: {
value: function() {
return this.split('');
},
name: "toArray"
}
},
name: "String",
path: "String",
namespace: "",
require: {},
import: {},
implements: {
String: true
}
}
},
glass: {
source: "require:
\tString: true
# runtime type tests
isFunction: (object) -> object? and typeof object is 'function'
isString: (object) -> object?.constructor is String
isArray: (object) -> Array.isArray object
isBoolean: (object) -> object? and typeof object is 'boolean'
isNumber: (object) -> object? and typeof object is 'number'
isObject: (object) -> typeof object is 'object'
isPlainObject: (object) -> object?.constructor is Object
isPrototype: (object) -> object? and object is object.constructor.prototype
isDate: (object) -> object?.constructor is Date
isPrimitive: (object) -> isString(object) or isBoolean(object) or isNumber(object) or isDate(object)
isPrivate: (property) -> property?[0] is '_'
# generic utility functions
values: (object) -> (value for key, value of object)
# generic patch method, uses patch method built into object if present
patch: (target, pathAndPatch...) ->
patch = JSONMergePatch.create.apply null, pathAndPatch
if isFunction target?.patch
target.patch patch
else
glass.JSONMergePatch.apply target, patch
# testing assertions
_getStackLocationInfo: (e, depth) ->
line = e.stack?.split('
')[depth]
return null unless line?
match = /\\(([\\w\\W]*?):(\\d+):(\\d+)\\)/.exec line
return {
file: match[1]
line: parseInt match[2]
column: parseInt match[3]
}
_throwAssertionFailure: (message) ->
try
throw new Error \"Assertion failed: \" + message
catch e
info = _getStackLocationInfo e, 3
if info?
_dumpFile info.file, info.line - 2, info.line + 2, info.line
throw e
_dumpFile: (file, from=1, to, highlight) ->
fs = require 'fs'
return unless fs?
try
content = fs.readFileSync(file).toString()
catch e
content = \"Source not found: #{e}\"
console.log '------------------------------------------------'
console.log file
console.log '------------------------------------------------'
number = 1
if content?
lines = content.split /
|
/
to ?= lines.length
for line in lines
lineNumber = number++
if lineNumber >= from and lineNumber <= to
num = String lineNumber
while num.length < 3
num += ' '
if lineNumber is highlight
`console.log(\"\\033[91m\" + num + \": \" + line + \"\\033[0m\");`
else
`console.log(num + \": \" + line);`
console.log '------------------------------------------------'
assert: (a) ->
_throwAssertionFailure JSON.stringify(a) unless a
assertTrue: (a) ->
_throwAssertionFailure JSON.stringify(a) + \" != true\" unless a is true
assertEquals: (a, b) ->
if JSON.stringify(a) isnt JSON.stringify(b)
_throwAssertionFailure JSON.stringify(a) + ' != ' + JSON.stringify(b)
# gets a unique string identifier for any object
getId:
do: ->
counter = 0
(a) ->
if a is null
return '__null__'
if a is undefined
return '__undefined__'
if typeof a is 'object' or typeof a is 'function'
return a.id ?= '__' + (counter++) + '__'
# 12 == \"12\" under this technique
return a.toString()
getType: (path) ->
array = if isArray path then path else path.split '.'
value = global
for step in path when value?
value = value[step]
throw new Error \"Type not found: #{path}\" unless isFunction value
value
test:
values: ->
assertEquals values({a:1,b:3,c:2}), [1,3,2]
patch: ->
x = {a:{foo:1,bar:3},b:2}
patch x, 'a', 'foo', 5
assertEquals x.a.foo, 5
",
input: "runtime\\glass.coffee",
content: {
require: {
String: "String"
},
isFunction: function(object) {
return (object != null) && typeof object === 'function';
},
isString: function(object) {
return (object != null ? object.constructor: void 0) === String;
},
isArray: function(object) {
return Array.isArray(object);
},
isBoolean: function(object) {
return (object != null) && typeof object === 'boolean';
},
isNumber: function(object) {
return (object != null) && typeof object === 'number';
},
isObject: function(object) {
return typeof object === 'object';
},
isPlainObject: function(object) {
return (object != null ? object.constructor: void 0) === Object;
},
isPrototype: function(object) {
return (object != null) && object === object.constructor.prototype;
},
isDate: function(object) {
return (object != null ? object.constructor: void 0) === Date;
},
isPrimitive: function(object) {
return isString(object) || isBoolean(object) || isNumber(object) || isDate(object);
},
isPrivate: function(property) {
return (property != null ? property[0] : void 0) === '_';
},
values: function(object) {
var key, value, _results;
_results = [];
for (key in object) {
value = object[key];
_results.push(value);
}
return _results;
},
patch: function() {
var patch, pathAndPatch, target;
target = arguments[0],
pathAndPatch = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
patch = JSONMergePatch.create.apply(null, pathAndPatch);
if (isFunction(target != null ? target.patch: void 0)) {
return target.patch(patch);
} else {
return glass.JSONMergePatch.apply(target, patch);
}
},
assert: function(a) {
if (!a) {
return _throwAssertionFailure(JSON.stringify(a));
}
},
assertTrue: function(a) {
if (a !== true) {
return _throwAssertionFailure(JSON.stringify(a) + " != true");
}
},
assertEquals: function(a, b) {
if (JSON.stringify(a) !== JSON.stringify(b)) {
return _throwAssertionFailure(JSON.stringify(a) + ' != ' + JSON.stringify(b));
}
},
getId: {
do: function() {
var counter;
counter = 0;
return function(a) {
var _ref;
if (a === null) {
return '__null__';
}
if (a === void 0) {
return '__undefined__';
}
if (typeof a === 'object' || typeof a === 'function') {
return (_ref = a.id) != null ? _ref: a.id = '__' + (counter++) + '__';
}
return a.toString();
};
}
},
getType: function(path) {
var array, step, value, _i, _len;
array = isArray(path) ? path: path.split('.');
value = global;
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
if (!isFunction(value)) {
throw new Error("Type not found: " + path);
}
return value;
},
test: {
values: function() {
return assertEquals(values({
a: 1,
b: 3,
c: 2
}), [1, 3, 2]);
},
patch: function() {
var x;
x = {
a: {
foo: 1,
bar: 3
},
b: 2
};
patch(x, 'a', 'foo', 5);
return assertEquals(x.a.foo, 5);
}
},
name: "glass",
path: "glass",
namespace: "",
import: {
"glass.JSONMergePatch": "JSONMergePatch",
"glass.isFunction": "isFunction",
"glass.isString": "isString",
"glass.isArray": "isArray",
"glass.isBoolean": "isBoolean",
"glass.isNumber": "isNumber",
"glass.isDate": "isDate",
"glass.values": "values",
"glass.patch": "patch",
"glass._getStackLocationInfo": "_getStackLocationInfo",
"glass._throwAssertionFailure": "_throwAssertionFailure",
"glass._dumpFile": "_dumpFile",
"glass.assertEquals": "assertEquals"
},
uri: "global:/glass"
}
},
"glass.Expression": {
source: "constructor: (op, args) ->
@op = op
@args = args if args?
@
properties:
op:
type: 'string'
args:
type: 'array'
test: ->
return
peg = require 'pegjs'
fs = require 'fs'
parserSource = fs.readFileSync 'runtime/glass/Expression/_parser.pegjs', 'utf8'
parser = peg.buildParser parserSource
tests =
\"a.b.c\": {op:\"get\",args:[{op:\"get\",args:[{op:\"ref\",args:[\"a\"]},\"b\"]},\"c\"]}
\"a.1\": {op:\"get\",args:[{op:\"ref\",args:[\"a\"]},1]}
\"true\": true
\"false\": false
\"45.8\": 45.8
\"(45.8)\": 45.8
\"((45.8))\": 45.8
\"alpha\": {op:\"ref\",args:[\"alpha\"]}
\"35 + true * 2\": {op:\"+\", args:[35, {op:\"*\", args:[true,2]}]}
\" 5 * ( 2 + 2 ) \": {op:\"*\", args:[5, {op:\"+\", args:[2,2]}]}
\" ! ! true\": {op:\"!\",args:[{op:\"!\",args:[true]}]}
\"5 + -x\": {op:\"+\",args:[5,{op:\"-\",args:[{op:\"ref\",args:[\"x\"]}]}]}
\"true == 5 >= 2\": {op:\"==\",args:[true,{op:\">=\",args:[5,2]}]}
\"1 or 2 and 3\": {op:\"or\",args:[1,{op:\"and\",args:[2,3]}]}
\"1 ? 2 : 3\": {op:\"?:\",args:[1,2,3]}
\"1 ? 2 : 3 ? 4 : 5\" : {op:\"?:\",args:[1,2,{op:\"?:\",args:[3,4,5]}]}
\"a()(1,2)\" : {op:\"call\",args:[{op:\"call\",args:[{op:\"ref\",args:[\"a\"]},[]]},[1,2]]}
\"@\" : {op:\"this\"}
\"@foo\" : {op:\"get\",args:[{op:\"this\"},\"foo\"]}
'\"hello\"': \"hello\"
'\"\\\\t\\
\\
\\\\b\\\\\\\\foo\\\\\\/\"' : \"\\t
\\b\\\\foo\\/\"
\"[]\": {op:\"array\",args:[]}
\"[1,2]\": {op:\"array\",args:[1,2]}
\"[1+2]\": {op:\"array\",args:[{op:\"+\",args:[1,2]}]}
\"{}\": {op:\"object\",args:[]}
'{\"a\":2}': {op:\"object\",args:[[\"a\",2]]}
'{\"a\":2,\"b\":1+2}': {op:\"object\",args:[[\"a\",2],[\"b\",{op:\"+\",args:[1,2]}]]}
'@\"alpha\"': {op:\"get\",args:[{op:\"this\"},\"alpha\"]}
'*': {op:\"values\",args:[]}
'*.*': {op:\"values\",args:[{op:\"values\",args:[]}]}
\"foo.*\": {op:\"values\",args:[{op:\"ref\",args:[\"foo\"]}]}
\"..\": {op:\"ancestor\",args:[1]}
\"...\": {op:\"ancestor\",args:[2]}
\"@*{1+2}\": {op:\"eval\",args:[{op:\"values\",args:[{op:\"this\"}]},{op:\"+\",args:[1,2]}]}
\"/\": {op:\"root\"}
\"/foo\": {op:\"get\",args:[{op:\"root\"},\"foo\"]}
\"/*\": {op:\"values\",args:[{op:\"root\"}]}
for text, expected of tests
result = parser.parse text
if JSON.stringify(result) is JSON.stringify(expected)
console.log 'Pass: ' + text
else
console.log text, JSON.stringify result
return
",
input: "runtime\\glass\\Expression.coffee",
content: {
constructor: function(op, args) {
this.op = op;
if (args != null) {
this.args = args;
}
return this;
},
properties: {
op: {
type: "string",
name: "op",
writable: true
},
args: {
type: "array",
name: "args",
writable: true
}
},
test: function() {
var expected, fs, parser, parserSource, peg, result, tests, text;
return;
peg = require('pegjs');
fs = require('fs');
parserSource = fs.readFileSync('runtime/glass/Expression/_parser.pegjs', 'utf8');
parser = peg.buildParser(parserSource);
tests = {
"a.b.c": {
op: "get",
args: [{
op: "get",
args: [{
op: "ref",
args: ["a"]
},
"b"]
},
"c"]
},
"a.1": {
op: "get",
args: [{
op: "ref",
args: ["a"]
},
1]
},
"true": true,
"false": false,
"45.8": 45.8,
"(45.8)": 45.8,
"((45.8))": 45.8,
"alpha": {
op: "ref",
args: ["alpha"]
},
"35 + true * 2": {
op: "+",
args: [35, {
op: "*",
args: [true, 2]
}]
},
" 5 * ( 2 + 2 ) ": {
op: "*",
args: [5, {
op: "+",
args: [2, 2]
}]
},
" ! ! true": {
op: "!",
args: [{
op: "!",
args: [true]
}]
},
"5 + -x": {
op: "+",
args: [5, {
op: "-",
args: [{
op: "ref",
args: ["x"]
}]
}]
},
"true == 5 >= 2": {
op: "==",
args: [true, {
op: ">=",
args: [5, 2]
}]
},
"1 or 2 and 3": {
op: "or",
args: [1, {
op: "and",
args: [2, 3]
}]
},
"1 ? 2 : 3": {
op: "?:",
args: [1, 2, 3]
},
"1 ? 2 : 3 ? 4 : 5": {
op: "?:",
args: [1, 2, {
op: "?:",
args: [3, 4, 5]
}]
},
"a()(1,2)": {
op: "call",
args: [{
op: "call",
args: [{
op: "ref",
args: ["a"]
},
[]]
},
[1, 2]]
},
"@": {
op: "this"
},
"@foo": {
op: "get",
args: [{
op: "this"
},
"foo"]
},
'"hello"': "hello",
'"\\t
\\b\\\\foo\\\/"': "\t
\b\\foo\/",
"[]": {
op: "array",
args: []
},
"[1,2]": {
op: "array",
args: [1, 2]
},
"[1+2]": {
op: "array",
args: [{
op: "+",
args: [1, 2]
}]
},
"{}": {
op: "object",
args: []
},
'{"a":2}': {
op: "object",
args: [["a", 2]]
},
'{"a":2,"b":1+2}': {
op: "object",
args: [["a", 2], ["b", {
op: "+",
args: [1, 2]
}]]
},
'@"alpha"': {
op: "get",
args: [{
op: "this"
},
"alpha"]
},
'*': {
op: "values",
args: []
},
'*.*': {
op: "values",
args: [{
op: "values",
args: []
}]
},
"foo.*": {
op: "values",
args: [{
op: "ref",
args: ["foo"]
}]
},
"..": {
op: "ancestor",
args: [1]
},
"...": {
op: "ancestor",
args: [2]
},
"@*{1+2}": {
op: "eval",
args: [{
op: "values",
args: [{
op: "this"
}]
},
{
op: "+",
args: [1, 2]
}]
},
"/": {
op: "root"
},
"/foo": {
op: "get",
args: [{
op: "root"
},
"foo"]
},
"/*": {
op: "values",
args: [{
op: "root"
}]
}
};
for (text in tests) {
expected = tests[text];
result = parser.parse(text);
if (JSON.stringify(result) === JSON.stringify(expected)) {
console.log('Pass: ' + text);
} else {
console.log(text, JSON.stringify(result));
}
}
},
name: "Expression",
path: "glass.Expression",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.Expression._parser": "_parser",
"glass.values": "values"
},
implements: {
"glass.Expression": true
},
uri: "global:/glass/Expression"
}
},
"glass.JSONMergePatch": {
source: "
# applies a patch to the target object and returns the resulting target
apply: (target, patch) ->
if target? and target isnt patch and isPlainObject(patch) and not isPrimitive(target)
for key, value of patch
if value is undefined
delete target[key]
else
target[key] = apply target[key], patch[key]
return target
else
return patch
# (path1, path2, path3.., patch) ->
create: ->
if arguments.length is 1
return arguments[0]
result = {}
current = result
for arg, i in arguments when i + 1 < arguments.length
last = i + 2 is arguments.length
current = current[arg] = if last then arguments[arguments.length-1] else {}
result
test: ->
assertEquals {a:{b:12}}, create 'a', 'b', 12
assertEquals {a:3}, apply({a:1,b:2}, {a:3,b:undefined})
",
input: "runtime\\glass\\JSONMergePatch.coffee",
content: {
apply: function(target, patch) {
var key, value;
if ((target != null) && target !== patch && isPlainObject(patch) && !isPrimitive(target)) {
for (key in patch) {
value = patch[key];
if (value === void 0) {
delete target[key];
} else {
target[key] = apply(target[key], patch[key]);
}
}
return target;
} else {
return patch;
}
},
create: function() {
var arg, current, i, last, result, _i, _len;
if (arguments.length === 1) {
return arguments[0];
}
result = {};
current = result;
for (i = _i = 0, _len = arguments.length; _i < _len; i = ++_i) {
arg = arguments[i];
if (! (i + 1 < arguments.length)) {
continue;
}
last = i + 2 === arguments.length;
current = current[arg] = last ? arguments[arguments.length - 1] : {};
}
return result;
},
test: function() {
assertEquals({
a: {
b: 12
}
},
create('a', 'b', 12));
return assertEquals({
a: 3
},
apply({
a: 1,
b: 2
},
{
a: 3,
b: void 0
}));
},
name: "JSONMergePatch",
path: "glass.JSONMergePatch",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONMergePatch.apply": "apply",
"glass.JSONMergePatch.create": "create",
"glass.isPlainObject": "isPlainObject",
"glass.isPrimitive": "isPrimitive",
"glass.patch": "patch",
"glass.assertEquals": "assertEquals"
},
uri: "global:/glass/JSONMergePatch"
}
},
"glass.JSONPointer": {
source: "# json pointer implementation as per
# http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-05
_decodeStep: (step) -> step.replace(/~1/g, '/').replace(/~0/g, '~')
_getLastStep: (pointer) ->
_decodeStep pointer.substring(pointer.lastIndexOf('/') + 1)
_getParent: (pointer) ->
if not pointer?.length
null
else
pointer.substring(0, pointer.lastIndexOf('/'))
toArray: (pointer) ->
for step in pointer.substring(1).split('/')
_decodeStep step
get: (doc, pointer) ->
value = doc
if pointer.length
path = toArray pointer
for step in path when value?
value = value[step]
value
set: (doc, pointer, value) ->
parentPointer = _getParent pointer
if parentPointer?
parent = get doc, parentPointer
lastStep = _getLastStep pointer
parent[lastStep] = value
value
test: ->
assertEquals _getParent(\"/a/b/c\"), \"/a/b\"
assertEquals _getParent(\"/a\"), \"\"
assertEquals _getParent(\"\"), null
assertEquals _getLastStep(\"/a/b/c\"), \"c\"
assertEquals _getLastStep(\"/a~0~1\"), \"a~/\"
assertEquals _getLastStep(\"\"), \"\"
# tests as per spec
doc = {
\"foo\": [\"bar\", \"baz\"],
\"\": 0,
\"a/b\": 1,
\"c%d\": 2,
\"e^f\": 3,
\"g|h\": 4,
\"i\\\\j\": 5,
\"k\\\"l\": 6,
\" \": 7,
\"m~n\": 8
}
assertEquals get(doc, \"\"), doc
assertEquals get(doc, \"/foo\"), [\"bar\", \"baz\"]
assertEquals get(doc, \"/foo/0\"), \"bar\"
assertEquals get(doc, \"/\"), 0
assertEquals get(doc, \"/a~1b\"), 1
assertEquals get(doc, \"/c%d\"), 2
assertEquals get(doc, \"/e^f\"), 3
assertEquals get(doc, \"/g|h\"), 4
assertEquals get(doc, \"/i\\\\j\"), 5
assertEquals get(doc, \"/k\\\"l\"), 6
assertEquals get(doc, \"/ \"), 7
assertEquals get(doc, \"/m~0n\"), 8
# now test set
assertEquals set(doc, \"/\", 10), 10
assertEquals doc[\"\"], 10
assertEquals set(doc, \"/foo/0\", 10), 10
assertEquals doc.foo[0], 10",
input: "runtime\\glass\\JSONPointer.coffee",
content: {
toArray: function(pointer) {
var step, _i, _len, _ref, _results;
_ref = pointer.substring(1).split('/');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
step = _ref[_i];
_results.push(_decodeStep(step));
}
return _results;
},
get: function(doc, pointer) {
var path, step, value, _i, _len;
value = doc;
if (pointer.length) {
path = toArray(pointer);
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
}
return value;
},
set: function(doc, pointer, value) {
var lastStep, parent, parentPointer;
parentPointer = _getParent(pointer);
if (parentPointer != null) {
parent = get(doc, parentPointer);
lastStep = _getLastStep(pointer);
parent[lastStep] = value;
}
return value;
},
test: function() {
var doc;
assertEquals(_getParent("/a/b/c"), "/a/b");
assertEquals(_getParent("/a"), "");
assertEquals(_getParent(""), null);
assertEquals(_getLastStep("/a/b/c"), "c");
assertEquals(_getLastStep("/a~0~1"), "a~/");
assertEquals(_getLastStep(""), "");
doc = {
"foo": ["bar", "baz"],
"": 0,
"a/b": 1,
"c%d": 2,
"e^f": 3,
"g|h": 4,
"i\\j": 5,
"k\"l": 6,
" ": 7,
"m~n": 8
};
assertEquals(get(doc, ""), doc);
assertEquals(get(doc, "/foo"), ["bar", "baz"]);
assertEquals(get(doc, "/foo/0"), "bar");
assertEquals(get(doc, "/"), 0);
assertEquals(get(doc, "/a~1b"), 1);
assertEquals(get(doc, "/c%d"), 2);
assertEquals(get(doc, "/e^f"), 3);
assertEquals(get(doc, "/g|h"), 4);
assertEquals(get(doc, "/i\\j"), 5);
assertEquals(get(doc, "/k\"l"), 6);
assertEquals(get(doc, "/ "), 7);
assertEquals(get(doc, "/m~0n"), 8);
assertEquals(set(doc, "/", 10), 10);
assertEquals(doc[""], 10);
assertEquals(set(doc, "/foo/0", 10), 10);
return assertEquals(doc.foo[0], 10);
},
name: "JSONPointer",
path: "glass.JSONPointer",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONPointer._decodeStep": "_decodeStep",
"glass.JSONPointer._getLastStep": "_getLastStep",
"glass.JSONPointer._getParent": "_getParent",
"glass.JSONPointer.toArray": "toArray",
"glass.JSONPointer.get": "get",
"glass.JSONPointer.set": "set",
"glass.assertEquals": "assertEquals"
},
uri: "global:/glass/JSONPointer"
}
},
"glass.Observable": {
source: "properties:
is: (type) -> @constructor.implements[type.path ? type] is true
watchers:
serializable: false
watch: (property, watcher) ->
if isFunction property
watcher = property
property = ''
id = getId watcher
@patch 'watchers', property, id, watcher
# returns a function which will remove the watch
=> @patch 'watchers', property, getId(watcher), undefined
patch: (change) ->
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
try
JSONMergePatch.apply this, change
catch e
console.log e
finally
@notify change
return
notify: (change) ->
if @watchers?
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
for property, watchers of @watchers
if property.length is 0 or change.hasOwnProperty property
changeArg = if property.length is 0 then change else change[property]
for id, watcher of watchers
watcher this, changeArg
return
toJSON: ->
values =
class: @constructor.path
# serialize statically defined properties
for name, property of @constructor.properties
value = @[name]
if property.serializable isnt false and not isFunction(value)
values[name] = value
# serialize custom properties if allowed by schema
if @constructor.additionalProperties isnt false
for own name, value of @ when not isPrivate name
values[name] = value
values
toString: -> @toJSON()
test:
toJSON: ->
# I need this test later
# on a class that actually has serializable properties
a = new Observable
a.x = 12
a.y = ->
a.z = true
assertEquals a, {class:'glass.Observable', x:12,z:true}
watchAll: ->
# we should actually be able to watch ourselves get added to watchers
# this is very meta.
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch watcher
# now make sure we were called with our own watcher
assert watchArgs[0] is a
assert watchArgs[1]?.watchers?[\"\"]?
# reset watchArgs, and watch something else
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assertEquals a.a, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {a:{b:3}}
# now unwatch
unwatch()
# make sure universal watcher is now empty
assertEquals a.watchers[\"\"], {}
# now reset and do a new event, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
watchProperty: ->
# watch a property
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch \"foo\", watcher
# now make sure we were not called
assert watchArgs.length is 0
# reset watchArgs, and watch something else
a.patch \"foo\", \"b\", 3
assertEquals a.foo, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {b:3}
# now reset and do a different property, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
# now unwatch
unwatch()
# make sure we no longer see foo
watchArgs.length = 0
a.patch \"foo\", \"b\", 4
assert watchArgs.length is 0
",
input: "runtime\\glass\\Observable.coffee",
content: {
properties: {
is: {
value: function(type) {
var _ref;
return this.constructor["implements"][(_ref = type.path) != null ? _ref: type] === true;
},
name: "is"
},
watchers: {
serializable: false,
name: "watchers",
writable: true
},
watch: {
value: function(property, watcher) {
var id, _this = this;
if (isFunction(property)) {
watcher = property;
property = '';
}
id = getId(watcher);
this.patch('watchers', property, id, watcher);
return function() {
return _this.patch('watchers', property, getId(watcher), void 0);
};
},
name: "watch"
},
patch: {
value: function(change) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
try {
JSONMergePatch.apply(this, change);
} catch(e) {
console.log(e);
} finally {
this.notify(change);
}
},
name: "patch"
},
notify: {
value: function(change) {
var changeArg, id, property, watcher, watchers, _ref;
if (this.watchers != null) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
_ref = this.watchers;
for (property in _ref) {
watchers = _ref[property];
if (property.length === 0 || change.hasOwnProperty(property)) {
changeArg = property.length === 0 ? change: change[property];
for (id in watchers) {
watcher = watchers[id];
watcher(this, changeArg);
}
}
}
}
},
name: "notify"
},
toJSON: {
value: function() {
var name, property, value, values, _ref;
values = {
"class": this.constructor.path
};
_ref = this.constructor.properties;
for (name in _ref) {
property = _ref[name];
value = this[name];
if (property.serializable !== false && !isFunction(value)) {
values[name] = value;
}
}
if (this.constructor.additionalProperties !== false) {
for (name in this) {
if (!__hasProp.call(this, name)) continue;
value = this[name];
if (!isPrivate(name)) {
values[name] = value;
}
}
}
return values;
},
name: "toJSON"
},
toString: {
value: function() {
return this.toJSON();
},
name: "toString"
}
},
test: {
toJSON: function() {
var a;
a = new Observable;
a.x = 12;
a.y = function() {};
a.z = true;
return assertEquals(a, {
"class": 'glass.Observable',
x: 12,
z: true
});
},
watchAll: function() {
var a, unwatch, watchArgs, watcher, _ref, _ref1;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch(watcher);
assert(watchArgs[0] === a);
assert(((_ref = watchArgs[1]) != null ? (_ref1 = _ref.watchers) != null ? _ref1[""] : void 0 : void 0) != null);
watchArgs.length = 0;
a.patch("a", "b", 3);
assertEquals(a.a, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
a: {
b: 3
}
});
unwatch();
assertEquals(a.watchers[""], {});
watchArgs.length = 0;
a.patch("a", "b", 3);
return assert(watchArgs.length === 0);
},
watchProperty: function() {
var a, unwatch, watchArgs, watcher;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch("foo", watcher);
assert(watchArgs.length === 0);
a.patch("foo", "b", 3);
assertEquals(a.foo, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
b: 3
});
watchArgs.length = 0;
a.patch("a", "b", 3);
assert(watchArgs.length === 0);
unwatch();
watchArgs.length = 0;
a.patch("foo", "b", 4);
return assert(watchArgs.length === 0);
}
},
name: "Observable",
path: "glass.Observable",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONMergePatch": "JSONMergePatch",
"glass.isFunction": "isFunction",
"glass.isPrivate": "isPrivate",
"glass.values": "values",
"glass.patch": "patch",
"glass.assert": "assert",
"glass.assertEquals": "assertEquals",
"glass.getId": "getId"
},
implements: {
"glass.Observable": true
},
uri: "global:/glass/Observable"
}
},
"glass.Component": {
source: "extends: 'Observable'
constructor: (properties) ->
@patch properties
# now site ourselves on our parent
if @parent
id = getId @
patch @parent, id, @
@
properties:
id:
description: 'string which uniquely identifies this component within its parent'
type: 'string'
parent:
description: 'the object that contains this component'
serializable: false
type: 'object'
disposed: false
dispose: -> @patch 'disposed', true
notify: (change) ->
Observable.prototype.notify.apply this, arguments
if change?.disposed
# dispose of any disposable children
for id, child of @ when child?.parent is @
child.dispose?()
# remove self from parent
if @id and @parent
patch @parent, @id, undefined
return
test:
lifecycle: ->
parent = new Component
assert not parent.id?
assert not parent.parent?
child = new Component parent:parent
# id should be automatically assigned
assert isString child.id
assert parent is child.parent
assert parent[child.id] is child
assert parent.hasOwnProperty child.id
parent.dispose()
assert child.disposed is true
assert not parent.hasOwnProperty child.id
nonEnumerability: ->
visibleKeys = (key for key of new Component)
assertEquals visibleKeys, []",
input: "runtime\\glass\\Component.coffee",
content: {
extends: ["glass.Observable"],
constructor: function(properties) {
var id;
this.patch(properties);
if (this.parent) {
id = getId(this);
patch(this.parent, id, this);
}
return this;
},
properties: {
id: {
description: "string which uniquely identifies this component within its parent",
type: "string",
name: "id",
writable: true
},
parent: {
description: "the object that contains this component",
serializable: false,
type: "object",
name: "parent",
writable: true
},
disposed: {
value: false,
name: "disposed",
writable: true
},
dispose: {
value: function() {
return this.patch('disposed', true);
},
name: "dispose"
},
notify: {
value: function(change) {
var child, id;
Observable.prototype.notify.apply(this, arguments);
if (change != null ? change.disposed: void 0) {
for (id in this) {
child = this[id];
if ((child != null ? child.parent: void 0) === this) {
if (typeof child.dispose === "function") {
child.dispose();
}
}
}
if (this.id && this.parent) {
patch(this.parent, this.id, void 0);
}
}
},
name: "notify"
}
},
test: {
lifecycle: function() {
var child, parent;
parent = new Component;
assert(!(parent.id != null));
assert(!(parent.parent != null));
child = new Component({
parent: parent
});
assert(isString(child.id));
assert(parent === child.parent);
assert(parent[child.id] === child);
assert(parent.hasOwnProperty(child.id));
parent.dispose();
assert(child.disposed === true);
return assert(!parent.hasOwnProperty(child.id));
},
nonEnumerability: function() {
var key, visibleKeys;
visibleKeys = (function() {
var _results;
_results = [];
for (key in new Component) {
_results.push(key);
}
return _results;
})();
return assertEquals(visibleKeys, []);
}
},
name: "Component",
path: "glass.Component",
namespace: "glass",
require: {
glass: "glass",
"glass.Observable": "Observable"
},
import: {
"glass.Observable": "Observable",
"glass.isString": "isString",
"glass.patch": "patch",
"glass.assert": "assert",
"glass.assertEquals": "assertEquals",
"glass.getId": "getId"
},
implements: {
"glass.Component": true,
"glass.Observable": true
},
uri: "global:/glass/Component"
}
},
"glass.Container": {
source: "extends: 'Observable'
properties:
watch: ->
unwatch: ->
",
input: "runtime\\glass\\Container.coffee",
content: {
extends: ["glass.Observable"],
properties: {
watch: {
value: function() {},
name: "watch"
},
unwatch: {
value: function() {},
name: "unwatch"
}
},
name: "Container",
path: "glass.Container",
namespace: "glass",
require: {
glass: "glass",
"glass.Observable": "Observable"
},
import: {},
implements: {
"glass.Container": true,
"glass.Observable": true
},
uri: "global:/glass/Container"
}
},
"glass.Expression._parser": {
source: "{
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e,array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++)
array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
}
start = expression
expression = conditional
conditional = e:or args:(\"?\" b:expression \":\" c:expression {return [b,c];})* {
while (args.length > 0) {
e = expr(\"?:\", [e].concat(args.pop()));
}
return e;
}
or = a:and b:((\"or\") and)* { return joinLeft(a,b); }
and = a:equality b:((\"and\") equality)* { return joinLeft(a,b); }
equality = a:rel b:((\"==\" / \"!=\") rel)* { return joinLeft(a,b); }
rel = a:sum b:((\"<=\" / \">=\" / \"<\" / \">\") sum)* { return joinLeft(a,b); }
sum = a:product b:((\"+\" / \"-\") product)* { return joinLeft(a,b); }
product = a:not b:((\"*\" / \"div\" / \"mod\") not)* { return joinLeft(a,b); }
not = ops:(s op:(\"!\" / \"~\" / \"+\" / \"-\") { return op; })* b:primary { return unaryRight(ops,b); }
primary = s a:(group / literal / path) s { return a; }
group = \"(\" a:expression \")\" { return a; }
literal = s a:(boolean / number / string / array / object) s { return a; }
boolean = a:(\"true\" / \"false\") { return a == \"true\"; }
number = a:([0-9]+ (\".\" [0-9]+)?) { return parseFloat(toString(a)); }
hex = [a-fA-F0-9]
// as per JSON http://www.json.org
string = a:( '\"' (
[\\u0000-\\u0021\\u0023-\\u005c\\u005e-\\uffff] // all unicode chars except \\ and \"
/ (\"\\\\\" (\"\\\"\" / \"\\\\\" / \"\\/\" / \"b\" / \"f\" / \"n\" / \"r\" / \"t\" / (\"u\" hex hex hex hex)))
)* '\"' )
{ return JSON.parse(toString(a)); }
array = \"[\" a:values \"]\" { return expr(\"array\", a); }
values = first:expression? args:(\",\" b:expression {return b;})* {
if (first != \"\") { args.unshift(first); } return args;
}
object = \"{\" a:keyvalues \"}\" { return expr(\"object\", a); }
keyvalue = s a:string s \":\" b:expression { return [a,b]; }
keyvalues = first:keyvalue? rest:(\",\" b:keyvalue {return b;})* {
if (first) { rest.unshift(first); } return rest;
}
ref = a:(\"//\" / \"/\" / \"$\" / \"**\" / \"*\" / \"..\" / \".\") b:slashProperty? {
e = expr(a); if (b) { b.args.unshift(e); e = b; } return e;
}
/ a:id { return expr(\"ref\", [a]); }
id = a:[a-z_]+ b:[a-z_0-9]* { return a.join('') + b.join(''); }
property = \"/\" a:slashProperty { return a; }
/ \"{\" a:expression \"}\" { return expr(\"{}\", [a]); } // locally scoped expression
/ \"[\" a:expression \"]\" { return expr(\"[]\", [a]); } // predicate
slashProperty = a:(id/number/string) { return expr(\"/\", [a]); }
/ a:(\"..\" / \"*\") { return expr(a, []); }
s \"space\" = [ ]* { return ''; }
path = a:root b:step* {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
}
root = a:implicitDotRoot b:dotStep? { return joinPath(a,b); }
/ explicitDotRoot
step = \".\" a:dotStep { return a; }
/ noDotStep
implicitDotRoot = \"/\" { return expr(\"root\"); }
/ \"@\" { return expr(\"this\"); }
/ \".\" a:\".\"+ { return expr(\"ancestor\", [a.length]); }
explicitDotRoot = a:id { return expr(\"ref\", [a]); }
/ \"*\" { return expr(\"values\", []); }
dotStep = a:(id / string / number) { return expr(\"get\", [a]); }
/ \"*\" { return expr(\"values\", []); }
noDotStep = \"{\" a:expression \"}\" { return expr(\"eval\", [a]); }
/ \"[\" a:expression \"]\" { return expr(\"pred\", [a]); }
/ \"(\" a:values \")\" { return expr(\"call\", [a]); }
",
input: "runtime\\glass\\Expression\\_parser.pegjs",
content: {
value: {
parse: function(input, startRule) {
var parseFunctions = {
"conditional": parse_conditional,
"or": parse_or,
"and": parse_and,
"equality": parse_equality,
"rel": parse_rel,
"sum": parse_sum,
"product": parse_product,
"not": parse_not,
"primary": parse_primary,
"group": parse_group,
"literal": parse_literal,
"boolean": parse_boolean,
"number": parse_number,
"hex": parse_hex,
"string": parse_string,
"array": parse_array,
"values": parse_values,
"object": parse_object,
"keyvalue": parse_keyvalue,
"keyvalues": parse_keyvalues,
"ref": parse_ref,
"id": parse_id,
"property": parse_property,
"slashProperty": parse_slashProperty,
"s": parse_s,
"path": parse_path,
"root": parse_root,
"step": parse_step,
"implicitDotRoot": parse_implicitDotRoot,
"explicitDotRoot": parse_explicitDotRoot,
"dotStep": parse_dotStep,
"noDotStep": parse_noDotStep
};
if (startRule !== undefined) {
if (parseFunctions[startRule] === undefined) {
throw new Error("Invalid rule name: " + quote(startRule) + ".");
}
} else {
startRule = "conditional";
}
var pos = 0;
var reportFailures = 0;
var rightmostFailuresPos = 0;
var rightmostFailuresExpected = [];
function padLeft(input, padding, length) {
var result = input;
var padLength = length - input.length;
for (var i = 0; i < padLength; i++) {
result = padding + result;
}
return result;
}
function escape(ch) {
var charCode = ch.charCodeAt(0);
var escapeChar;
var length;
if (charCode <= 0xFF) {
escapeChar = 'x';
length = 2;
} else {
escapeChar = 'u';
length = 4;
}
return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
}
function matchFailed(failure) {
if (pos < rightmostFailuresPos) {
return;
}
if (pos > rightmostFailuresPos) {
rightmostFailuresPos = pos;
rightmostFailuresExpected = [];
}
rightmostFailuresExpected.push(failure);
}
function parse_conditional() {
var result0, result1, result2, result3, result4, result5;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_or();
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, e, args) {
while (args.length > 0) {
e = expr("?:", [e].concat(args.pop()));
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_or() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_and();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_and() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_equality();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_equality() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_rel();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_rel() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_sum();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_sum() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_product();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_product() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_not();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_not() {
var result0, result1, result2;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = [];
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
while (result1 !== null) {
result0.push(result1);
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
}
if (result0 !== null) {
result1 = parse_primary();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, ops, b) {
return unaryRight(ops, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_primary() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_group();
if (result1 === null) {
result1 = parse_literal();
if (result1 === null) {
result1 = parse_path();
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_group() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_literal() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_boolean();
if (result1 === null) {
result1 = parse_number();
if (result1 === null) {
result1 = parse_string();
if (result1 === null) {
result1 = parse_array();
if (result1 === null) {
result1 = parse_object();
}
}
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_boolean() {
var result0;
var pos0;
pos0 = pos;
if (input.substr(pos, 4) === "true") {
result0 = "true";
pos += 4;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"true\"");
}
}
if (result0 === null) {
if (input.substr(pos, 5) === "false") {
result0 = "false";
pos += 5;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"false\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a == "true";
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_number() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
pos2 = pos;
if (input.charCodeAt(pos) === 46) {
result1 = ".";
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result1 !== null) {
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result3 !== null) {
result2 = [];
while (result3 !== null) {
result2.push(result3);
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result2 = null;
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos2;
}
} else {
result1 = null;
pos = pos2;
}
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return parseFloat(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_hex() {
var result0;
if (/^[a-fA-F0-9]/.test(input.charAt(pos))) {
result0 = input.charAt(pos);
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("[a-fA-F0-9]");
}
}
return result0;
}
function parse_string() {
var result0, result1, result2, result3, result4, result5, result6, result7;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 34) {
result0 = "\"";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result0 !== null) {
result1 = [];
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
}
if (result1 !== null) {
if (input.charCodeAt(pos) === 34) {
result2 = "\"";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return JSON.parse(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_array() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("array", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_values() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_conditional();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, args) {
if (first != "") {
args.unshift(first);
}
return args;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_object() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_keyvalues();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("object", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalue() {
var result0, result1, result2, result3, result4;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_string();
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
if (input.charCodeAt(pos) === 58) {
result3 = ":";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result3 !== null) {
result4 = parse_conditional();
if (result4 !== null) {
result0 = [result0, result1, result2, result3, result4];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return [a, b];
})(pos0, result0[1], result0[4]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalues() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_keyvalue();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, rest) {
if (first) {
rest.unshift(first);
}
return rest;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_ref() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.substr(pos, 2) === "//") {
result0 = "//";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"//\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 36) {
result0 = "$";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"$\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "**") {
result0 = "**";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"**\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
}
}
}
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
e = expr(a);
if (b) {
b.args.unshift(e);
e = b;
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_id() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
result1 = [];
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return a.join('') + b.join('');
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_property() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("{}", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("[]", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_slashProperty() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_number();
if (result0 === null) {
result0 = parse_string();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("/", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(a, []);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_s() {
var result0, result1;
var pos0;
reportFailures++;
pos0 = pos;
result0 = [];
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
while (result1 !== null) {
result0.push(result1);
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
}
if (result0 !== null) {
result0 = (function(offset) {
return '';
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
reportFailures--;
if (reportFailures === 0 && result0 === null) {
matchFailed("space");
}
return result0;
}
function parse_path() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_root();
if (result0 !== null) {
result1 = [];
result2 = parse_step();
while (result2 !== null) {
result1.push(result2);
result2 = parse_step();
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_root() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_implicitDotRoot();
if (result0 !== null) {
result1 = parse_dotStep();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinPath(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_explicitDotRoot();
}
return result0;
}
function parse_step() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
result1 = parse_dotStep();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_noDotStep();
}
return result0;
}
function parse_implicitDotRoot() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("root");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 64) {
result0 = "@";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"@\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("this");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result2 !== null) {
result1 = [];
while (result2 !== null) {
result1.push(result2);
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
} else {
result1 = null;
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ancestor", [a.length]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_explicitDotRoot() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_dotStep() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_string();
if (result0 === null) {
result0 = parse_number();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("get", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_noDotStep() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("eval", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("pred", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("call", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function cleanupExpected(expected) {
expected.sort();
var lastExpected = null;
var cleanExpected = [];
for (var i = 0; i < expected.length; i++) {
if (expected[i] !== lastExpected) {
cleanExpected.push(expected[i]);
lastExpected = expected[i];
}
}
return cleanExpected;
}
function computeErrorPosition() {
/*
* The first idea was to use |String.split| to break the input up to the
* error position along newlines and derive the line and column from
* there. However IE's |split| implementation is so broken that it was
* enough to prevent it.
*/
var line = 1;
var column = 1;
var seenCR = false;
for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
var ch = input.charAt(i);
if (ch === "
") {
if (!seenCR) {
line++;
}
column = 1;
seenCR = false;
} else if (ch === "
" || ch === "\u2028" || ch === "\u2029") {
line++;
column = 1;
seenCR = true;
} else {
column++;
seenCR = false;
}
}
return {
line: line,
column: column
};
}
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e, array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++) array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
var result = parseFunctions[startRule]();
/*
* The parser is now in one of the following three states:
*
* 1. The parser successfully parsed the whole input.
*
* - |result !== null|
* - |pos === input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 2. The parser successfully parsed only a part of the input.
*
* - |result !== null|
* - |pos < input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 3. The parser did not successfully parse any part of the input.
*
* - |result === null|
* - |pos === 0|
* - |rightmostFailuresExpected| contains at least one failure
*
* All code following this comment (including called functions) must
* handle these states.
*/
if (result === null || pos !== input.length) {
var offset = Math.max(pos, rightmostFailuresPos);
var found = offset < input.length ? input.charAt(offset) : null;
var errorPosition = computeErrorPosition();
throw new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column);
}
return result;
},
toSource: function() {
return this._source;
},
SyntaxError: function(expected, found, offset, line, column) {
function buildMessage(expected, found) {
var expectedHumanized, foundHumanized;
switch (expected.length) {
case 0:
expectedHumanized = "end of input";
break;
case 1:
expectedHumanized = expected[0];
break;
default:
expectedHumanized = expected.slice(0, expected.length - 1).join(", ") + " or " + expected[expected.length - 1];
}
foundHumanized = found ? quote(found) : "end of input";
return "Expected " + expectedHumanized + " but " + foundHumanized + " found.";
}
this.name = "SyntaxError";
this.expected = expected;
this.found = found;
this.message = buildMessage(expected, found);
this.offset = offset;
this.line = line;
this.column = column;
}
},
name: "_parser",
path: "glass.Expression._parser",
namespace: "glass.Expression",
require: {
"glass.Expression": "Expression"
},
import: {
"glass.values": "values"
},
uri: "global:/glass/Expression/_parser"
}
}
}
} | {
options: {
input: {
dir: "runtime",
match: /\.(coffee|pegjs)$/
},
output: {
dir: "www/js"
},
script: {
includes: "www/includes.html",
prefix: "/js/"
},
module: {
main: "glass.js",
prefix: "./www/js/"
},
debug: "buildlog.html",
test: "glass.allTests",
addon: {
pregenerate: {
addUri: function(schema) {
var content, type, typeName, _ref2, _ref3;
_ref2 = schema.types;
for (typeName in _ref2) {
type = _ref2[typeName];
content = type.content;
if (content.extension) {
continue;
}
if ((_ref3 = content.uri) == null) {
content.uri = "global:/" + (content.path.replace(/\./g, '/'));
}
}
return schema;
}
}
},
namespace: ""
},
types: {
String: {
source: "extension: true
properties:
\tstartsWith: (s) -> @slice(0,s.length) is s
\tendsWith: (s) -> @slice(-s.length) is s
\tcontains: (s) -> @indexOf(s) >= 0
\ttoArray: () -> @split ''",
input: "runtime\\String.coffee",
content: {
extension: true,
properties: {
startsWith: {
value: function(s) {
return this.slice(0, s.length) === s;
},
name: "startsWith"
},
endsWith: {
value: function(s) {
return this.slice( - s.length) === s;
},
name: "endsWith"
},
contains: {
value: function(s) {
return this.indexOf(s) >= 0;
},
name: "contains"
},
toArray: {
value: function() {
return this.split('');
},
name: "toArray"
}
},
name: "String",
path: "String",
namespace: "",
require: {},
import: {},
implements: {
String: true
}
}
},
glass: {
source: "require:
\tString: true
# runtime type tests
isFunction: (object) -> object? and typeof object is 'function'
isString: (object) -> object?.constructor is String
isArray: (object) -> Array.isArray object
isBoolean: (object) -> object? and typeof object is 'boolean'
isNumber: (object) -> object? and typeof object is 'number'
isObject: (object) -> typeof object is 'object'
isPlainObject: (object) -> object?.constructor is Object
isPrototype: (object) -> object? and object is object.constructor.prototype
isDate: (object) -> object?.constructor is Date
isPrimitive: (object) -> isString(object) or isBoolean(object) or isNumber(object) or isDate(object)
isPrivate: (property) -> property?[0] is '_'
# generic utility functions
values: (object) -> (value for key, value of object)
# generic patch method, uses patch method built into object if present
patch: (target, pathAndPatch...) ->
patch = JSONMergePatch.create.apply null, pathAndPatch
if isFunction target?.patch
target.patch patch
else
glass.JSONMergePatch.apply target, patch
# testing assertions
_getStackLocationInfo: (e, depth) ->
line = e.stack?.split('
')[depth]
return null unless line?
match = /\\(([\\w\\W]*?):(\\d+):(\\d+)\\)/.exec line
return {
file: match[1]
line: parseInt match[2]
column: parseInt match[3]
}
_throwAssertionFailure: (message) ->
try
throw new Error \"Assertion failed: \" + message
catch e
info = _getStackLocationInfo e, 3
if info?
_dumpFile info.file, info.line - 2, info.line + 2, info.line
throw e
_dumpFile: (file, from=1, to, highlight) ->
fs = require 'fs'
return unless fs?
try
content = fs.readFileSync(file).toString()
catch e
content = \"Source not found: #{e}\"
console.log '------------------------------------------------'
console.log file
console.log '------------------------------------------------'
number = 1
if content?
lines = content.split /
|
/
to ?= lines.length
for line in lines
lineNumber = number++
if lineNumber >= from and lineNumber <= to
num = String lineNumber
while num.length < 3
num += ' '
if lineNumber is highlight
`console.log(\"\\033[91m\" + num + \": \" + line + \"\\033[0m\");`
else
`console.log(num + \": \" + line);`
console.log '------------------------------------------------'
assert: (a) ->
_throwAssertionFailure JSON.stringify(a) unless a
assertTrue: (a) ->
_throwAssertionFailure JSON.stringify(a) + \" != true\" unless a is true
assertEquals: (a, b) ->
if JSON.stringify(a) isnt JSON.stringify(b)
_throwAssertionFailure JSON.stringify(a) + ' != ' + JSON.stringify(b)
# gets a unique string identifier for any object
getId:
do: ->
counter = 0
(a) ->
if a is null
return '__null__'
if a is undefined
return '__undefined__'
if typeof a is 'object' or typeof a is 'function'
return a.id ?= '__' + (counter++) + '__'
# 12 == \"12\" under this technique
return a.toString()
getType: (path) ->
array = if isArray path then path else path.split '.'
value = global
for step in path when value?
value = value[step]
throw new Error \"Type not found: #{path}\" unless isFunction value
value
test:
values: ->
assertEquals values({a:1,b:3,c:2}), [1,3,2]
patch: ->
x = {a:{foo:1,bar:3},b:2}
patch x, 'a', 'foo', 5
assertEquals x.a.foo, 5
",
input: "runtime\\glass.coffee",
content: {
require: {
String: "String"
},
isFunction: function(object) {
return (object != null) && typeof object === 'function';
},
isString: function(object) {
return (object != null ? object.constructor: void 0) === String;
},
isArray: function(object) {
return Array.isArray(object);
},
isBoolean: function(object) {
return (object != null) && typeof object === 'boolean';
},
isNumber: function(object) {
return (object != null) && typeof object === 'number';
},
isObject: function(object) {
return typeof object === 'object';
},
isPlainObject: function(object) {
return (object != null ? object.constructor: void 0) === Object;
},
isPrototype: function(object) {
return (object != null) && object === object.constructor.prototype;
},
isDate: function(object) {
return (object != null ? object.constructor: void 0) === Date;
},
isPrimitive: function(object) {
return isString(object) || isBoolean(object) || isNumber(object) || isDate(object);
},
isPrivate: function(property) {
return (property != null ? property[0] : void 0) === '_';
},
values: function(object) {
var key, value, _results;
_results = [];
for (key in object) {
value = object[key];
_results.push(value);
}
return _results;
},
patch: function() {
var patch, pathAndPatch, target;
target = arguments[0],
pathAndPatch = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
patch = JSONMergePatch.create.apply(null, pathAndPatch);
if (isFunction(target != null ? target.patch: void 0)) {
return target.patch(patch);
} else {
return glass.JSONMergePatch.apply(target, patch);
}
},
assert: function(a) {
if (!a) {
return _throwAssertionFailure(JSON.stringify(a));
}
},
assertTrue: function(a) {
if (a !== true) {
return _throwAssertionFailure(JSON.stringify(a) + " != true");
}
},
assertEquals: function(a, b) {
if (JSON.stringify(a) !== JSON.stringify(b)) {
return _throwAssertionFailure(JSON.stringify(a) + ' != ' + JSON.stringify(b));
}
},
getId: {
do: function() {
var counter;
counter = 0;
return function(a) {
var _ref;
if (a === null) {
return '__null__';
}
if (a === void 0) {
return '__undefined__';
}
if (typeof a === 'object' || typeof a === 'function') {
return (_ref = a.id) != null ? _ref: a.id = '__' + (counter++) + '__';
}
return a.toString();
};
}
},
getType: function(path) {
var array, step, value, _i, _len;
array = isArray(path) ? path: path.split('.');
value = global;
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
if (!isFunction(value)) {
throw new Error("Type not found: " + path);
}
return value;
},
test: {
values: function() {
return assertEquals(values({
a: 1,
b: 3,
c: 2
}), [1, 3, 2]);
},
patch: function() {
var x;
x = {
a: {
foo: 1,
bar: 3
},
b: 2
};
patch(x, 'a', 'foo', 5);
return assertEquals(x.a.foo, 5);
}
},
name: "glass",
path: "glass",
namespace: "",
import: {
"glass.JSONMergePatch": "JSONMergePatch",
"glass.isFunction": "isFunction",
"glass.isString": "isString",
"glass.isArray": "isArray",
"glass.isBoolean": "isBoolean",
"glass.isNumber": "isNumber",
"glass.isDate": "isDate",
"glass.values": "values",
"glass.patch": "patch",
"glass._getStackLocationInfo": "_getStackLocationInfo",
"glass._throwAssertionFailure": "_throwAssertionFailure",
"glass._dumpFile": "_dumpFile",
"glass.assertEquals": "assertEquals"
},
uri: "global:/glass"
}
},
"glass.Expression": {
source: "constructor: (op, args) ->
@op = op
@args = args if args?
@
properties:
op:
type: 'string'
args:
type: 'array'
test: ->
return
peg = require 'pegjs'
fs = require 'fs'
parserSource = fs.readFileSync 'runtime/glass/Expression/_parser.pegjs', 'utf8'
parser = peg.buildParser parserSource
tests =
\"a.b.c\": {op:\"get\",args:[{op:\"get\",args:[{op:\"ref\",args:[\"a\"]},\"b\"]},\"c\"]}
\"a.1\": {op:\"get\",args:[{op:\"ref\",args:[\"a\"]},1]}
\"true\": true
\"false\": false
\"45.8\": 45.8
\"(45.8)\": 45.8
\"((45.8))\": 45.8
\"alpha\": {op:\"ref\",args:[\"alpha\"]}
\"35 + true * 2\": {op:\"+\", args:[35, {op:\"*\", args:[true,2]}]}
\" 5 * ( 2 + 2 ) \": {op:\"*\", args:[5, {op:\"+\", args:[2,2]}]}
\" ! ! true\": {op:\"!\",args:[{op:\"!\",args:[true]}]}
\"5 + -x\": {op:\"+\",args:[5,{op:\"-\",args:[{op:\"ref\",args:[\"x\"]}]}]}
\"true == 5 >= 2\": {op:\"==\",args:[true,{op:\">=\",args:[5,2]}]}
\"1 or 2 and 3\": {op:\"or\",args:[1,{op:\"and\",args:[2,3]}]}
\"1 ? 2 : 3\": {op:\"?:\",args:[1,2,3]}
\"1 ? 2 : 3 ? 4 : 5\" : {op:\"?:\",args:[1,2,{op:\"?:\",args:[3,4,5]}]}
\"a()(1,2)\" : {op:\"call\",args:[{op:\"call\",args:[{op:\"ref\",args:[\"a\"]},[]]},[1,2]]}
\"@\" : {op:\"this\"}
\"@foo\" : {op:\"get\",args:[{op:\"this\"},\"foo\"]}
'\"hello\"': \"hello\"
'\"\\\\t\\
\\
\\\\b\\\\\\\\foo\\\\\\/\"' : \"\\t
\\b\\\\foo\\/\"
\"[]\": {op:\"array\",args:[]}
\"[1,2]\": {op:\"array\",args:[1,2]}
\"[1+2]\": {op:\"array\",args:[{op:\"+\",args:[1,2]}]}
\"{}\": {op:\"object\",args:[]}
'{\"a\":2}': {op:\"object\",args:[[\"a\",2]]}
'{\"a\":2,\"b\":1+2}': {op:\"object\",args:[[\"a\",2],[\"b\",{op:\"+\",args:[1,2]}]]}
'@\"alpha\"': {op:\"get\",args:[{op:\"this\"},\"alpha\"]}
'*': {op:\"values\",args:[]}
'*.*': {op:\"values\",args:[{op:\"values\",args:[]}]}
\"foo.*\": {op:\"values\",args:[{op:\"ref\",args:[\"foo\"]}]}
\"..\": {op:\"ancestor\",args:[1]}
\"...\": {op:\"ancestor\",args:[2]}
\"@*{1+2}\": {op:\"eval\",args:[{op:\"values\",args:[{op:\"this\"}]},{op:\"+\",args:[1,2]}]}
\"/\": {op:\"root\"}
\"/foo\": {op:\"get\",args:[{op:\"root\"},\"foo\"]}
\"/*\": {op:\"values\",args:[{op:\"root\"}]}
for text, expected of tests
result = parser.parse text
if JSON.stringify(result) is JSON.stringify(expected)
console.log 'Pass: ' + text
else
console.log text, JSON.stringify result
return
",
input: "runtime\\glass\\Expression.coffee",
content: {
constructor: function(op, args) {
this.op = op;
if (args != null) {
this.args = args;
}
return this;
},
properties: {
op: {
type: "string",
name: "op",
writable: true
},
args: {
type: "array",
name: "args",
writable: true
}
},
test: function() {
var expected, fs, parser, parserSource, peg, result, tests, text;
return;
peg = require('pegjs');
fs = require('fs');
parserSource = fs.readFileSync('runtime/glass/Expression/_parser.pegjs', 'utf8');
parser = peg.buildParser(parserSource);
tests = {
"a.b.c": {
op: "get",
args: [{
op: "get",
args: [{
op: "ref",
args: ["a"]
},
"b"]
},
"c"]
},
"a.1": {
op: "get",
args: [{
op: "ref",
args: ["a"]
},
1]
},
"true": true,
"false": false,
"45.8": 45.8,
"(45.8)": 45.8,
"((45.8))": 45.8,
"alpha": {
op: "ref",
args: ["alpha"]
},
"35 + true * 2": {
op: "+",
args: [35, {
op: "*",
args: [true, 2]
}]
},
" 5 * ( 2 + 2 ) ": {
op: "*",
args: [5, {
op: "+",
args: [2, 2]
}]
},
" ! ! true": {
op: "!",
args: [{
op: "!",
args: [true]
}]
},
"5 + -x": {
op: "+",
args: [5, {
op: "-",
args: [{
op: "ref",
args: ["x"]
}]
}]
},
"true == 5 >= 2": {
op: "==",
args: [true, {
op: ">=",
args: [5, 2]
}]
},
"1 or 2 and 3": {
op: "or",
args: [1, {
op: "and",
args: [2, 3]
}]
},
"1 ? 2 : 3": {
op: "?:",
args: [1, 2, 3]
},
"1 ? 2 : 3 ? 4 : 5": {
op: "?:",
args: [1, 2, {
op: "?:",
args: [3, 4, 5]
}]
},
"a()(1,2)": {
op: "call",
args: [{
op: "call",
args: [{
op: "ref",
args: ["a"]
},
[]]
},
[1, 2]]
},
"@": {
op: "this"
},
"@foo": {
op: "get",
args: [{
op: "this"
},
"foo"]
},
'"hello"': "hello",
'"\\t
\\b\\\\foo\\\/"': "\t
\b\\foo\/",
"[]": {
op: "array",
args: []
},
"[1,2]": {
op: "array",
args: [1, 2]
},
"[1+2]": {
op: "array",
args: [{
op: "+",
args: [1, 2]
}]
},
"{}": {
op: "object",
args: []
},
'{"a":2}': {
op: "object",
args: [["a", 2]]
},
'{"a":2,"b":1+2}': {
op: "object",
args: [["a", 2], ["b", {
op: "+",
args: [1, 2]
}]]
},
'@"alpha"': {
op: "get",
args: [{
op: "this"
},
"alpha"]
},
'*': {
op: "values",
args: []
},
'*.*': {
op: "values",
args: [{
op: "values",
args: []
}]
},
"foo.*": {
op: "values",
args: [{
op: "ref",
args: ["foo"]
}]
},
"..": {
op: "ancestor",
args: [1]
},
"...": {
op: "ancestor",
args: [2]
},
"@*{1+2}": {
op: "eval",
args: [{
op: "values",
args: [{
op: "this"
}]
},
{
op: "+",
args: [1, 2]
}]
},
"/": {
op: "root"
},
"/foo": {
op: "get",
args: [{
op: "root"
},
"foo"]
},
"/*": {
op: "values",
args: [{
op: "root"
}]
}
};
for (text in tests) {
expected = tests[text];
result = parser.parse(text);
if (JSON.stringify(result) === JSON.stringify(expected)) {
console.log('Pass: ' + text);
} else {
console.log(text, JSON.stringify(result));
}
}
},
name: "Expression",
path: "glass.Expression",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.Expression._parser": "_parser",
"glass.values": "values"
},
implements: {
"glass.Expression": true
},
uri: "global:/glass/Expression"
}
},
"glass.JSONMergePatch": {
source: "
# applies a patch to the target object and returns the resulting target
apply: (target, patch) ->
if target? and target isnt patch and isPlainObject(patch) and not isPrimitive(target)
for key, value of patch
if value is undefined
delete target[key]
else
target[key] = apply target[key], patch[key]
return target
else
return patch
# (path1, path2, path3.., patch) ->
create: ->
if arguments.length is 1
return arguments[0]
result = {}
current = result
for arg, i in arguments when i + 1 < arguments.length
last = i + 2 is arguments.length
current = current[arg] = if last then arguments[arguments.length-1] else {}
result
test: ->
assertEquals {a:{b:12}}, create 'a', 'b', 12
assertEquals {a:3}, apply({a:1,b:2}, {a:3,b:undefined})
",
input: "runtime\\glass\\JSONMergePatch.coffee",
content: {
apply: function(target, patch) {
var key, value;
if ((target != null) && target !== patch && isPlainObject(patch) && !isPrimitive(target)) {
for (key in patch) {
value = patch[key];
if (value === void 0) {
delete target[key];
} else {
target[key] = apply(target[key], patch[key]);
}
}
return target;
} else {
return patch;
}
},
create: function() {
var arg, current, i, last, result, _i, _len;
if (arguments.length === 1) {
return arguments[0];
}
result = {};
current = result;
for (i = _i = 0, _len = arguments.length; _i < _len; i = ++_i) {
arg = arguments[i];
if (! (i + 1 < arguments.length)) {
continue;
}
last = i + 2 === arguments.length;
current = current[arg] = last ? arguments[arguments.length - 1] : {};
}
return result;
},
test: function() {
assertEquals({
a: {
b: 12
}
},
create('a', 'b', 12));
return assertEquals({
a: 3
},
apply({
a: 1,
b: 2
},
{
a: 3,
b: void 0
}));
},
name: "JSONMergePatch",
path: "glass.JSONMergePatch",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONMergePatch.apply": "apply",
"glass.JSONMergePatch.create": "create",
"glass.isPlainObject": "isPlainObject",
"glass.isPrimitive": "isPrimitive",
"glass.patch": "patch",
"glass.assertEquals": "assertEquals"
},
uri: "global:/glass/JSONMergePatch"
}
},
"glass.JSONPointer": {
source: "# json pointer implementation as per
# http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-05
_decodeStep: (step) -> step.replace(/~1/g, '/').replace(/~0/g, '~')
_getLastStep: (pointer) ->
_decodeStep pointer.substring(pointer.lastIndexOf('/') + 1)
_getParent: (pointer) ->
if not pointer?.length
null
else
pointer.substring(0, pointer.lastIndexOf('/'))
toArray: (pointer) ->
for step in pointer.substring(1).split('/')
_decodeStep step
get: (doc, pointer) ->
value = doc
if pointer.length
path = toArray pointer
for step in path when value?
value = value[step]
value
set: (doc, pointer, value) ->
parentPointer = _getParent pointer
if parentPointer?
parent = get doc, parentPointer
lastStep = _getLastStep pointer
parent[lastStep] = value
value
test: ->
assertEquals _getParent(\"/a/b/c\"), \"/a/b\"
assertEquals _getParent(\"/a\"), \"\"
assertEquals _getParent(\"\"), null
assertEquals _getLastStep(\"/a/b/c\"), \"c\"
assertEquals _getLastStep(\"/a~0~1\"), \"a~/\"
assertEquals _getLastStep(\"\"), \"\"
# tests as per spec
doc = {
\"foo\": [\"bar\", \"baz\"],
\"\": 0,
\"a/b\": 1,
\"c%d\": 2,
\"e^f\": 3,
\"g|h\": 4,
\"i\\\\j\": 5,
\"k\\\"l\": 6,
\" \": 7,
\"m~n\": 8
}
assertEquals get(doc, \"\"), doc
assertEquals get(doc, \"/foo\"), [\"bar\", \"baz\"]
assertEquals get(doc, \"/foo/0\"), \"bar\"
assertEquals get(doc, \"/\"), 0
assertEquals get(doc, \"/a~1b\"), 1
assertEquals get(doc, \"/c%d\"), 2
assertEquals get(doc, \"/e^f\"), 3
assertEquals get(doc, \"/g|h\"), 4
assertEquals get(doc, \"/i\\\\j\"), 5
assertEquals get(doc, \"/k\\\"l\"), 6
assertEquals get(doc, \"/ \"), 7
assertEquals get(doc, \"/m~0n\"), 8
# now test set
assertEquals set(doc, \"/\", 10), 10
assertEquals doc[\"\"], 10
assertEquals set(doc, \"/foo/0\", 10), 10
assertEquals doc.foo[0], 10",
input: "runtime\\glass\\JSONPointer.coffee",
content: {
toArray: function(pointer) {
var step, _i, _len, _ref, _results;
_ref = pointer.substring(1).split('/');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
step = _ref[_i];
_results.push(_decodeStep(step));
}
return _results;
},
get: function(doc, pointer) {
var path, step, value, _i, _len;
value = doc;
if (pointer.length) {
path = toArray(pointer);
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
}
return value;
},
set: function(doc, pointer, value) {
var lastStep, parent, parentPointer;
parentPointer = _getParent(pointer);
if (parentPointer != null) {
parent = get(doc, parentPointer);
lastStep = _getLastStep(pointer);
parent[lastStep] = value;
}
return value;
},
test: function() {
var doc;
assertEquals(_getParent("/a/b/c"), "/a/b");
assertEquals(_getParent("/a"), "");
assertEquals(_getParent(""), null);
assertEquals(_getLastStep("/a/b/c"), "c");
assertEquals(_getLastStep("/a~0~1"), "a~/");
assertEquals(_getLastStep(""), "");
doc = {
"foo": ["bar", "baz"],
"": 0,
"a/b": 1,
"c%d": 2,
"e^f": 3,
"g|h": 4,
"i\\j": 5,
"k\"l": 6,
" ": 7,
"m~n": 8
};
assertEquals(get(doc, ""), doc);
assertEquals(get(doc, "/foo"), ["bar", "baz"]);
assertEquals(get(doc, "/foo/0"), "bar");
assertEquals(get(doc, "/"), 0);
assertEquals(get(doc, "/a~1b"), 1);
assertEquals(get(doc, "/c%d"), 2);
assertEquals(get(doc, "/e^f"), 3);
assertEquals(get(doc, "/g|h"), 4);
assertEquals(get(doc, "/i\\j"), 5);
assertEquals(get(doc, "/k\"l"), 6);
assertEquals(get(doc, "/ "), 7);
assertEquals(get(doc, "/m~0n"), 8);
assertEquals(set(doc, "/", 10), 10);
assertEquals(doc[""], 10);
assertEquals(set(doc, "/foo/0", 10), 10);
return assertEquals(doc.foo[0], 10);
},
name: "JSONPointer",
path: "glass.JSONPointer",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONPointer._decodeStep": "_decodeStep",
"glass.JSONPointer._getLastStep": "_getLastStep",
"glass.JSONPointer._getParent": "_getParent",
"glass.JSONPointer.toArray": "toArray",
"glass.JSONPointer.get": "get",
"glass.JSONPointer.set": "set",
"glass.assertEquals": "assertEquals"
},
uri: "global:/glass/JSONPointer"
}
},
"glass.Observable": {
source: "properties:
is: (type) -> @constructor.implements[type.path ? type] is true
watchers:
serializable: false
watch: (property, watcher) ->
if isFunction property
watcher = property
property = ''
id = getId watcher
@patch 'watchers', property, id, watcher
# returns a function which will remove the watch
=> @patch 'watchers', property, getId(watcher), undefined
patch: (change) ->
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
try
JSONMergePatch.apply this, change
catch e
console.log e
finally
@notify change
return
notify: (change) ->
if @watchers?
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
for property, watchers of @watchers
if property.length is 0 or change.hasOwnProperty property
changeArg = if property.length is 0 then change else change[property]
for id, watcher of watchers
watcher this, changeArg
return
toJSON: ->
values =
class: @constructor.path
# serialize statically defined properties
for name, property of @constructor.properties
value = @[name]
if property.serializable isnt false and not isFunction(value)
values[name] = value
# serialize custom properties if allowed by schema
if @constructor.additionalProperties isnt false
for own name, value of @ when not isPrivate name
values[name] = value
values
toString: -> @toJSON()
test:
toJSON: ->
# I need this test later
# on a class that actually has serializable properties
a = new Observable
a.x = 12
a.y = ->
a.z = true
assertEquals a, {class:'glass.Observable', x:12,z:true}
watchAll: ->
# we should actually be able to watch ourselves get added to watchers
# this is very meta.
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch watcher
# now make sure we were called with our own watcher
assert watchArgs[0] is a
assert watchArgs[1]?.watchers?[\"\"]?
# reset watchArgs, and watch something else
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assertEquals a.a, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {a:{b:3}}
# now unwatch
unwatch()
# make sure universal watcher is now empty
assertEquals a.watchers[\"\"], {}
# now reset and do a new event, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
watchProperty: ->
# watch a property
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch \"foo\", watcher
# now make sure we were not called
assert watchArgs.length is 0
# reset watchArgs, and watch something else
a.patch \"foo\", \"b\", 3
assertEquals a.foo, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {b:3}
# now reset and do a different property, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
# now unwatch
unwatch()
# make sure we no longer see foo
watchArgs.length = 0
a.patch \"foo\", \"b\", 4
assert watchArgs.length is 0
",
input: "runtime\\glass\\Observable.coffee",
content: {
properties: {
is: {
value: function(type) {
var _ref;
return this.constructor["implements"][(_ref = type.path) != null ? _ref: type] === true;
},
name: "is"
},
watchers: {
serializable: false,
name: "watchers",
writable: true
},
watch: {
value: function(property, watcher) {
var id, _this = this;
if (isFunction(property)) {
watcher = property;
property = '';
}
id = getId(watcher);
this.patch('watchers', property, id, watcher);
return function() {
return _this.patch('watchers', property, getId(watcher), void 0);
};
},
name: "watch"
},
patch: {
value: function(change) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
try {
JSONMergePatch.apply(this, change);
} catch(e) {
console.log(e);
} finally {
this.notify(change);
}
},
name: "patch"
},
notify: {
value: function(change) {
var changeArg, id, property, watcher, watchers, _ref;
if (this.watchers != null) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
_ref = this.watchers;
for (property in _ref) {
watchers = _ref[property];
if (property.length === 0 || change.hasOwnProperty(property)) {
changeArg = property.length === 0 ? change: change[property];
for (id in watchers) {
watcher = watchers[id];
watcher(this, changeArg);
}
}
}
}
},
name: "notify"
},
toJSON: {
value: function() {
var name, property, value, values, _ref;
values = {
"class": this.constructor.path
};
_ref = this.constructor.properties;
for (name in _ref) {
property = _ref[name];
value = this[name];
if (property.serializable !== false && !isFunction(value)) {
values[name] = value;
}
}
if (this.constructor.additionalProperties !== false) {
for (name in this) {
if (!__hasProp.call(this, name)) continue;
value = this[name];
if (!isPrivate(name)) {
values[name] = value;
}
}
}
return values;
},
name: "toJSON"
},
toString: {
value: function() {
return this.toJSON();
},
name: "toString"
}
},
test: {
toJSON: function() {
var a;
a = new Observable;
a.x = 12;
a.y = function() {};
a.z = true;
return assertEquals(a, {
"class": 'glass.Observable',
x: 12,
z: true
});
},
watchAll: function() {
var a, unwatch, watchArgs, watcher, _ref, _ref1;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch(watcher);
assert(watchArgs[0] === a);
assert(((_ref = watchArgs[1]) != null ? (_ref1 = _ref.watchers) != null ? _ref1[""] : void 0 : void 0) != null);
watchArgs.length = 0;
a.patch("a", "b", 3);
assertEquals(a.a, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
a: {
b: 3
}
});
unwatch();
assertEquals(a.watchers[""], {});
watchArgs.length = 0;
a.patch("a", "b", 3);
return assert(watchArgs.length === 0);
},
watchProperty: function() {
var a, unwatch, watchArgs, watcher;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch("foo", watcher);
assert(watchArgs.length === 0);
a.patch("foo", "b", 3);
assertEquals(a.foo, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
b: 3
});
watchArgs.length = 0;
a.patch("a", "b", 3);
assert(watchArgs.length === 0);
unwatch();
watchArgs.length = 0;
a.patch("foo", "b", 4);
return assert(watchArgs.length === 0);
}
},
name: "Observable",
path: "glass.Observable",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONMergePatch": "JSONMergePatch",
"glass.isFunction": "isFunction",
"glass.isPrivate": "isPrivate",
"glass.values": "values",
"glass.patch": "patch",
"glass.assert": "assert",
"glass.assertEquals": "assertEquals",
"glass.getId": "getId"
},
implements: {
"glass.Observable": true
},
uri: "global:/glass/Observable"
}
},
"glass.Component": {
source: "extends: 'Observable'
constructor: (properties) ->
@patch properties
# now site ourselves on our parent
if @parent
id = getId @
patch @parent, id, @
@
properties:
id:
description: 'string which uniquely identifies this component within its parent'
type: 'string'
parent:
description: 'the object that contains this component'
serializable: false
type: 'object'
disposed: false
dispose: -> @patch 'disposed', true
notify: (change) ->
Observable.prototype.notify.apply this, arguments
if change?.disposed
# dispose of any disposable children
for id, child of @ when child?.parent is @
child.dispose?()
# remove self from parent
if @id and @parent
patch @parent, @id, undefined
return
test:
lifecycle: ->
parent = new Component
assert not parent.id?
assert not parent.parent?
child = new Component parent:parent
# id should be automatically assigned
assert isString child.id
assert parent is child.parent
assert parent[child.id] is child
assert parent.hasOwnProperty child.id
parent.dispose()
assert child.disposed is true
assert not parent.hasOwnProperty child.id
nonEnumerability: ->
visibleKeys = (key for key of new Component)
assertEquals visibleKeys, []",
input: "runtime\\glass\\Component.coffee",
content: {
extends: ["glass.Observable"],
constructor: function(properties) {
var id;
this.patch(properties);
if (this.parent) {
id = getId(this);
patch(this.parent, id, this);
}
return this;
},
properties: {
id: {
description: "string which uniquely identifies this component within its parent",
type: "string",
name: "id",
writable: true
},
parent: {
description: "the object that contains this component",
serializable: false,
type: "object",
name: "parent",
writable: true
},
disposed: {
value: false,
name: "disposed",
writable: true
},
dispose: {
value: function() {
return this.patch('disposed', true);
},
name: "dispose"
},
notify: {
value: function(change) {
var child, id;
Observable.prototype.notify.apply(this, arguments);
if (change != null ? change.disposed: void 0) {
for (id in this) {
child = this[id];
if ((child != null ? child.parent: void 0) === this) {
if (typeof child.dispose === "function") {
child.dispose();
}
}
}
if (this.id && this.parent) {
patch(this.parent, this.id, void 0);
}
}
},
name: "notify"
}
},
test: {
lifecycle: function() {
var child, parent;
parent = new Component;
assert(!(parent.id != null));
assert(!(parent.parent != null));
child = new Component({
parent: parent
});
assert(isString(child.id));
assert(parent === child.parent);
assert(parent[child.id] === child);
assert(parent.hasOwnProperty(child.id));
parent.dispose();
assert(child.disposed === true);
return assert(!parent.hasOwnProperty(child.id));
},
nonEnumerability: function() {
var key, visibleKeys;
visibleKeys = (function() {
var _results;
_results = [];
for (key in new Component) {
_results.push(key);
}
return _results;
})();
return assertEquals(visibleKeys, []);
}
},
name: "Component",
path: "glass.Component",
namespace: "glass",
require: {
glass: "glass",
"glass.Observable": "Observable"
},
import: {
"glass.Observable": "Observable",
"glass.isString": "isString",
"glass.patch": "patch",
"glass.assert": "assert",
"glass.assertEquals": "assertEquals",
"glass.getId": "getId"
},
implements: {
"glass.Component": true,
"glass.Observable": true
},
uri: "global:/glass/Component"
}
},
"glass.Container": {
source: "extends: 'Observable'
properties:
watch: ->
unwatch: ->
",
input: "runtime\\glass\\Container.coffee",
content: {
extends: ["glass.Observable"],
properties: {
watch: {
value: function() {},
name: "watch"
},
unwatch: {
value: function() {},
name: "unwatch"
}
},
name: "Container",
path: "glass.Container",
namespace: "glass",
require: {
glass: "glass",
"glass.Observable": "Observable"
},
import: {},
implements: {
"glass.Container": true,
"glass.Observable": true
},
uri: "global:/glass/Container"
}
},
"glass.Expression._parser": {
source: "{
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e,array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++)
array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
}
start = expression
expression = conditional
conditional = e:or args:(\"?\" b:expression \":\" c:expression {return [b,c];})* {
while (args.length > 0) {
e = expr(\"?:\", [e].concat(args.pop()));
}
return e;
}
or = a:and b:((\"or\") and)* { return joinLeft(a,b); }
and = a:equality b:((\"and\") equality)* { return joinLeft(a,b); }
equality = a:rel b:((\"==\" / \"!=\") rel)* { return joinLeft(a,b); }
rel = a:sum b:((\"<=\" / \">=\" / \"<\" / \">\") sum)* { return joinLeft(a,b); }
sum = a:product b:((\"+\" / \"-\") product)* { return joinLeft(a,b); }
product = a:not b:((\"*\" / \"div\" / \"mod\") not)* { return joinLeft(a,b); }
not = ops:(s op:(\"!\" / \"~\" / \"+\" / \"-\") { return op; })* b:primary { return unaryRight(ops,b); }
primary = s a:(group / literal / path) s { return a; }
group = \"(\" a:expression \")\" { return a; }
literal = s a:(boolean / number / string / array / object) s { return a; }
boolean = a:(\"true\" / \"false\") { return a == \"true\"; }
number = a:([0-9]+ (\".\" [0-9]+)?) { return parseFloat(toString(a)); }
hex = [a-fA-F0-9]
// as per JSON http://www.json.org
string = a:( '\"' (
[\\u0000-\\u0021\\u0023-\\u005c\\u005e-\\uffff] // all unicode chars except \\ and \"
/ (\"\\\\\" (\"\\\"\" / \"\\\\\" / \"\\/\" / \"b\" / \"f\" / \"n\" / \"r\" / \"t\" / (\"u\" hex hex hex hex)))
)* '\"' )
{ return JSON.parse(toString(a)); }
array = \"[\" a:values \"]\" { return expr(\"array\", a); }
values = first:expression? args:(\",\" b:expression {return b;})* {
if (first != \"\") { args.unshift(first); } return args;
}
object = \"{\" a:keyvalues \"}\" { return expr(\"object\", a); }
keyvalue = s a:string s \":\" b:expression { return [a,b]; }
keyvalues = first:keyvalue? rest:(\",\" b:keyvalue {return b;})* {
if (first) { rest.unshift(first); } return rest;
}
ref = a:(\"//\" / \"/\" / \"$\" / \"**\" / \"*\" / \"..\" / \".\") b:slashProperty? {
e = expr(a); if (b) { b.args.unshift(e); e = b; } return e;
}
/ a:id { return expr(\"ref\", [a]); }
id = a:[a-z_]+ b:[a-z_0-9]* { return a.join('') + b.join(''); }
property = \"/\" a:slashProperty { return a; }
/ \"{\" a:expression \"}\" { return expr(\"{}\", [a]); } // locally scoped expression
/ \"[\" a:expression \"]\" { return expr(\"[]\", [a]); } // predicate
slashProperty = a:(id/number/string) { return expr(\"/\", [a]); }
/ a:(\"..\" / \"*\") { return expr(a, []); }
s \"space\" = [ ]* { return ''; }
path = a:root b:step* {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
}
root = a:implicitDotRoot b:dotStep? { return joinPath(a,b); }
/ explicitDotRoot
step = \".\" a:dotStep { return a; }
/ noDotStep
implicitDotRoot = \"/\" { return expr(\"root\"); }
/ \"@\" { return expr(\"this\"); }
/ \".\" a:\".\"+ { return expr(\"ancestor\", [a.length]); }
explicitDotRoot = a:id { return expr(\"ref\", [a]); }
/ \"*\" { return expr(\"values\", []); }
dotStep = a:(id / string / number) { return expr(\"get\", [a]); }
/ \"*\" { return expr(\"values\", []); }
noDotStep = \"{\" a:expression \"}\" { return expr(\"eval\", [a]); }
/ \"[\" a:expression \"]\" { return expr(\"pred\", [a]); }
/ \"(\" a:values \")\" { return expr(\"call\", [a]); }
",
input: "runtime\\glass\\Expression\\_parser.pegjs",
content: {
value: {
parse: function(input, startRule) {
var parseFunctions = {
"conditional": parse_conditional,
"or": parse_or,
"and": parse_and,
"equality": parse_equality,
"rel": parse_rel,
"sum": parse_sum,
"product": parse_product,
"not": parse_not,
"primary": parse_primary,
"group": parse_group,
"literal": parse_literal,
"boolean": parse_boolean,
"number": parse_number,
"hex": parse_hex,
"string": parse_string,
"array": parse_array,
"values": parse_values,
"object": parse_object,
"keyvalue": parse_keyvalue,
"keyvalues": parse_keyvalues,
"ref": parse_ref,
"id": parse_id,
"property": parse_property,
"slashProperty": parse_slashProperty,
"s": parse_s,
"path": parse_path,
"root": parse_root,
"step": parse_step,
"implicitDotRoot": parse_implicitDotRoot,
"explicitDotRoot": parse_explicitDotRoot,
"dotStep": parse_dotStep,
"noDotStep": parse_noDotStep
};
if (startRule !== undefined) {
if (parseFunctions[startRule] === undefined) {
throw new Error("Invalid rule name: " + quote(startRule) + ".");
}
} else {
startRule = "conditional";
}
var pos = 0;
var reportFailures = 0;
var rightmostFailuresPos = 0;
var rightmostFailuresExpected = [];
function padLeft(input, padding, length) {
var result = input;
var padLength = length - input.length;
for (var i = 0; i < padLength; i++) {
result = padding + result;
}
return result;
}
function escape(ch) {
var charCode = ch.charCodeAt(0);
var escapeChar;
var length;
if (charCode <= 0xFF) {
escapeChar = 'x';
length = 2;
} else {
escapeChar = 'u';
length = 4;
}
return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
}
function matchFailed(failure) {
if (pos < rightmostFailuresPos) {
return;
}
if (pos > rightmostFailuresPos) {
rightmostFailuresPos = pos;
rightmostFailuresExpected = [];
}
rightmostFailuresExpected.push(failure);
}
function parse_conditional() {
var result0, result1, result2, result3, result4, result5;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_or();
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, e, args) {
while (args.length > 0) {
e = expr("?:", [e].concat(args.pop()));
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_or() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_and();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_and() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_equality();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_equality() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_rel();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_rel() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_sum();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_sum() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_product();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_product() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_not();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_not() {
var result0, result1, result2;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = [];
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
while (result1 !== null) {
result0.push(result1);
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
}
if (result0 !== null) {
result1 = parse_primary();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, ops, b) {
return unaryRight(ops, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_primary() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_group();
if (result1 === null) {
result1 = parse_literal();
if (result1 === null) {
result1 = parse_path();
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_group() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_literal() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_boolean();
if (result1 === null) {
result1 = parse_number();
if (result1 === null) {
result1 = parse_string();
if (result1 === null) {
result1 = parse_array();
if (result1 === null) {
result1 = parse_object();
}
}
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_boolean() {
var result0;
var pos0;
pos0 = pos;
if (input.substr(pos, 4) === "true") {
result0 = "true";
pos += 4;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"true\"");
}
}
if (result0 === null) {
if (input.substr(pos, 5) === "false") {
result0 = "false";
pos += 5;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"false\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a == "true";
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_number() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
pos2 = pos;
if (input.charCodeAt(pos) === 46) {
result1 = ".";
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result1 !== null) {
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result3 !== null) {
result2 = [];
while (result3 !== null) {
result2.push(result3);
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result2 = null;
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos2;
}
} else {
result1 = null;
pos = pos2;
}
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return parseFloat(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_hex() {
var result0;
if (/^[a-fA-F0-9]/.test(input.charAt(pos))) {
result0 = input.charAt(pos);
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("[a-fA-F0-9]");
}
}
return result0;
}
function parse_string() {
var result0, result1, result2, result3, result4, result5, result6, result7;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 34) {
result0 = "\"";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result0 !== null) {
result1 = [];
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
}
if (result1 !== null) {
if (input.charCodeAt(pos) === 34) {
result2 = "\"";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return JSON.parse(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_array() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("array", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_values() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_conditional();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, args) {
if (first != "") {
args.unshift(first);
}
return args;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_object() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_keyvalues();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("object", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalue() {
var result0, result1, result2, result3, result4;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_string();
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
if (input.charCodeAt(pos) === 58) {
result3 = ":";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result3 !== null) {
result4 = parse_conditional();
if (result4 !== null) {
result0 = [result0, result1, result2, result3, result4];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return [a, b];
})(pos0, result0[1], result0[4]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalues() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_keyvalue();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, rest) {
if (first) {
rest.unshift(first);
}
return rest;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_ref() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.substr(pos, 2) === "//") {
result0 = "//";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"//\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 36) {
result0 = "$";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"$\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "**") {
result0 = "**";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"**\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
}
}
}
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
e = expr(a);
if (b) {
b.args.unshift(e);
e = b;
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_id() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
result1 = [];
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return a.join('') + b.join('');
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_property() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("{}", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("[]", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_slashProperty() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_number();
if (result0 === null) {
result0 = parse_string();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("/", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(a, []);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_s() {
var result0, result1;
var pos0;
reportFailures++;
pos0 = pos;
result0 = [];
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
while (result1 !== null) {
result0.push(result1);
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
}
if (result0 !== null) {
result0 = (function(offset) {
return '';
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
reportFailures--;
if (reportFailures === 0 && result0 === null) {
matchFailed("space");
}
return result0;
}
function parse_path() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_root();
if (result0 !== null) {
result1 = [];
result2 = parse_step();
while (result2 !== null) {
result1.push(result2);
result2 = parse_step();
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_root() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_implicitDotRoot();
if (result0 !== null) {
result1 = parse_dotStep();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinPath(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_explicitDotRoot();
}
return result0;
}
function parse_step() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
result1 = parse_dotStep();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_noDotStep();
}
return result0;
}
function parse_implicitDotRoot() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("root");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 64) {
result0 = "@";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"@\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("this");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result2 !== null) {
result1 = [];
while (result2 !== null) {
result1.push(result2);
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
} else {
result1 = null;
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ancestor", [a.length]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_explicitDotRoot() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_dotStep() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_string();
if (result0 === null) {
result0 = parse_number();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("get", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_noDotStep() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("eval", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("pred", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("call", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function cleanupExpected(expected) {
expected.sort();
var lastExpected = null;
var cleanExpected = [];
for (var i = 0; i < expected.length; i++) {
if (expected[i] !== lastExpected) {
cleanExpected.push(expected[i]);
lastExpected = expected[i];
}
}
return cleanExpected;
}
function computeErrorPosition() {
/*
* The first idea was to use |String.split| to break the input up to the
* error position along newlines and derive the line and column from
* there. However IE's |split| implementation is so broken that it was
* enough to prevent it.
*/
var line = 1;
var column = 1;
var seenCR = false;
for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
var ch = input.charAt(i);
if (ch === "
") {
if (!seenCR) {
line++;
}
column = 1;
seenCR = false;
} else if (ch === "
" || ch === "\u2028" || ch === "\u2029") {
line++;
column = 1;
seenCR = true;
} else {
column++;
seenCR = false;
}
}
return {
line: line,
column: column
};
}
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e, array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++) array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
var result = parseFunctions[startRule]();
/*
* The parser is now in one of the following three states:
*
* 1. The parser successfully parsed the whole input.
*
* - |result !== null|
* - |pos === input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 2. The parser successfully parsed only a part of the input.
*
* - |result !== null|
* - |pos < input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 3. The parser did not successfully parse any part of the input.
*
* - |result === null|
* - |pos === 0|
* - |rightmostFailuresExpected| contains at least one failure
*
* All code following this comment (including called functions) must
* handle these states.
*/
if (result === null || pos !== input.length) {
var offset = Math.max(pos, rightmostFailuresPos);
var found = offset < input.length ? input.charAt(offset) : null;
var errorPosition = computeErrorPosition();
throw new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column);
}
return result;
},
toSource: function() {
return this._source;
},
SyntaxError: function(expected, found, offset, line, column) {
function buildMessage(expected, found) {
var expectedHumanized, foundHumanized;
switch (expected.length) {
case 0:
expectedHumanized = "end of input";
break;
case 1:
expectedHumanized = expected[0];
break;
default:
expectedHumanized = expected.slice(0, expected.length - 1).join(", ") + " or " + expected[expected.length - 1];
}
foundHumanized = found ? quote(found) : "end of input";
return "Expected " + expectedHumanized + " but " + foundHumanized + " found.";
}
this.name = "SyntaxError";
this.expected = expected;
this.found = found;
this.message = buildMessage(expected, found);
this.offset = offset;
this.line = line;
this.column = column;
}
},
name: "_parser",
path: "glass.Expression._parser",
namespace: "glass.Expression",
require: {
"glass.Expression": "Expression"
},
import: {
"glass.values": "values"
},
uri: "global:/glass/Expression/_parser"
}
}
}
} | {
options: {
input: {
dir: "runtime",
match: /\.(coffee|pegjs)$/
},
output: {
dir: "www/js"
},
script: {
includes: "www/includes.html",
prefix: "/js/"
},
module: {
main: "glass.js",
prefix: "./www/js/"
},
debug: "buildlog.html",
test: "glass.allTests",
addon: {
pregenerate: {
addUri: function(schema) {
var content, type, typeName, _ref2, _ref3;
_ref2 = schema.types;
for (typeName in _ref2) {
type = _ref2[typeName];
content = type.content;
if (content.extension) {
continue;
}
if ((_ref3 = content.uri) == null) {
content.uri = "global:/" + (content.path.replace(/\./g, '/'));
}
}
return schema;
}
}
},
namespace: ""
},
types: {
String: {
source: "extension: true
properties:
\tstartsWith: (s) -> @slice(0,s.length) is s
\tendsWith: (s) -> @slice(-s.length) is s
\tcontains: (s) -> @indexOf(s) >= 0
\ttoArray: () -> @split ''",
input: "runtime\\String.coffee",
content: {
extension: true,
properties: {
startsWith: {
value: function(s) {
return this.slice(0, s.length) === s;
},
name: "startsWith"
},
endsWith: {
value: function(s) {
return this.slice( - s.length) === s;
},
name: "endsWith"
},
contains: {
value: function(s) {
return this.indexOf(s) >= 0;
},
name: "contains"
},
toArray: {
value: function() {
return this.split('');
},
name: "toArray"
}
},
name: "String",
path: "String",
namespace: "",
require: {},
import: {},
implements: {
String: true
}
}
},
glass: {
source: "require:
\tString: true
# runtime type tests
isFunction: (object) -> object? and typeof object is 'function'
isString: (object) -> object?.constructor is String
isArray: (object) -> Array.isArray object
isBoolean: (object) -> object? and typeof object is 'boolean'
isNumber: (object) -> object? and typeof object is 'number'
isObject: (object) -> typeof object is 'object'
isPlainObject: (object) -> object?.constructor is Object
isPrototype: (object) -> object? and object is object.constructor.prototype
isDate: (object) -> object?.constructor is Date
isPrimitive: (object) -> isString(object) or isBoolean(object) or isNumber(object) or isDate(object)
isPrivate: (property) -> property?[0] is '_'
# generic utility functions
values: (object) -> (value for key, value of object)
# generic patch method, uses patch method built into object if present
patch: (target, pathAndPatch...) ->
patch = JSONMergePatch.create.apply null, pathAndPatch
if isFunction target?.patch
target.patch patch
else
glass.JSONMergePatch.apply target, patch
# testing assertions
_getStackLocationInfo: (e, depth) ->
line = e.stack?.split('
')[depth]
return null unless line?
match = /\\(([\\w\\W]*?):(\\d+):(\\d+)\\)/.exec line
return {
file: match[1]
line: parseInt match[2]
column: parseInt match[3]
}
_throwAssertionFailure: (message) ->
try
throw new Error \"Assertion failed: \" + message
catch e
info = _getStackLocationInfo e, 3
if info?
_dumpFile info.file, info.line - 2, info.line + 2, info.line
throw e
_dumpFile: (file, from=1, to, highlight) ->
fs = require 'fs'
return unless fs?
try
content = fs.readFileSync(file).toString()
catch e
content = \"Source not found: #{e}\"
console.log '------------------------------------------------'
console.log file
console.log '------------------------------------------------'
number = 1
if content?
lines = content.split /
|
/
to ?= lines.length
for line in lines
lineNumber = number++
if lineNumber >= from and lineNumber <= to
num = String lineNumber
while num.length < 3
num += ' '
if lineNumber is highlight
`console.log(\"\\033[91m\" + num + \": \" + line + \"\\033[0m\");`
else
`console.log(num + \": \" + line);`
console.log '------------------------------------------------'
assert: (a) ->
_throwAssertionFailure JSON.stringify(a) unless a
assertTrue: (a) ->
_throwAssertionFailure JSON.stringify(a) + \" != true\" unless a is true
assertEquals: (a, b) ->
if JSON.stringify(a) isnt JSON.stringify(b)
_throwAssertionFailure JSON.stringify(a) + ' != ' + JSON.stringify(b)
# gets a unique string identifier for any object
getId:
do: ->
counter = 0
(a) ->
if a is null
return '__null__'
if a is undefined
return '__undefined__'
if typeof a is 'object' or typeof a is 'function'
return a.id ?= '__' + (counter++) + '__'
# 12 == \"12\" under this technique
return a.toString()
getType: (path) ->
array = if isArray path then path else path.split '.'
value = global
for step in path when value?
value = value[step]
throw new Error \"Type not found: #{path}\" unless isFunction value
value
test:
values: ->
assertEquals values({a:1,b:3,c:2}), [1,3,2]
patch: ->
x = {a:{foo:1,bar:3},b:2}
patch x, 'a', 'foo', 5
assertEquals x.a.foo, 5
",
input: "runtime\\glass.coffee",
content: {
require: {
String: "String"
},
isFunction: function(object) {
return (object != null) && typeof object === 'function';
},
isString: function(object) {
return (object != null ? object.constructor: void 0) === String;
},
isArray: function(object) {
return Array.isArray(object);
},
isBoolean: function(object) {
return (object != null) && typeof object === 'boolean';
},
isNumber: function(object) {
return (object != null) && typeof object === 'number';
},
isObject: function(object) {
return typeof object === 'object';
},
isPlainObject: function(object) {
return (object != null ? object.constructor: void 0) === Object;
},
isPrototype: function(object) {
return (object != null) && object === object.constructor.prototype;
},
isDate: function(object) {
return (object != null ? object.constructor: void 0) === Date;
},
isPrimitive: function(object) {
return isString(object) || isBoolean(object) || isNumber(object) || isDate(object);
},
isPrivate: function(property) {
return (property != null ? property[0] : void 0) === '_';
},
values: function(object) {
var key, value, _results;
_results = [];
for (key in object) {
value = object[key];
_results.push(value);
}
return _results;
},
patch: function() {
var patch, pathAndPatch, target;
target = arguments[0],
pathAndPatch = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
patch = JSONMergePatch.create.apply(null, pathAndPatch);
if (isFunction(target != null ? target.patch: void 0)) {
return target.patch(patch);
} else {
return glass.JSONMergePatch.apply(target, patch);
}
},
assert: function(a) {
if (!a) {
return _throwAssertionFailure(JSON.stringify(a));
}
},
assertTrue: function(a) {
if (a !== true) {
return _throwAssertionFailure(JSON.stringify(a) + " != true");
}
},
assertEquals: function(a, b) {
if (JSON.stringify(a) !== JSON.stringify(b)) {
return _throwAssertionFailure(JSON.stringify(a) + ' != ' + JSON.stringify(b));
}
},
getId: {
do: function() {
var counter;
counter = 0;
return function(a) {
var _ref;
if (a === null) {
return '__null__';
}
if (a === void 0) {
return '__undefined__';
}
if (typeof a === 'object' || typeof a === 'function') {
return (_ref = a.id) != null ? _ref: a.id = '__' + (counter++) + '__';
}
return a.toString();
};
}
},
getType: function(path) {
var array, step, value, _i, _len;
array = isArray(path) ? path: path.split('.');
value = global;
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
if (!isFunction(value)) {
throw new Error("Type not found: " + path);
}
return value;
},
test: {
values: function() {
return assertEquals(values({
a: 1,
b: 3,
c: 2
}), [1, 3, 2]);
},
patch: function() {
var x;
x = {
a: {
foo: 1,
bar: 3
},
b: 2
};
patch(x, 'a', 'foo', 5);
return assertEquals(x.a.foo, 5);
}
},
name: "glass",
path: "glass",
namespace: "",
import: {
"glass.JSONMergePatch": "JSONMergePatch",
"glass.isFunction": "isFunction",
"glass.isString": "isString",
"glass.isArray": "isArray",
"glass.isBoolean": "isBoolean",
"glass.isNumber": "isNumber",
"glass.isDate": "isDate",
"glass.values": "values",
"glass.patch": "patch",
"glass._getStackLocationInfo": "_getStackLocationInfo",
"glass._throwAssertionFailure": "_throwAssertionFailure",
"glass._dumpFile": "_dumpFile",
"glass.assertEquals": "assertEquals"
},
uri: "global:/glass"
}
},
"glass.Expression": {
source: "constructor: (op, args) ->
@op = op
@args = args if args?
@
properties:
op:
type: 'string'
args:
type: 'array'
test: ->
return
peg = require 'pegjs'
fs = require 'fs'
parserSource = fs.readFileSync 'runtime/glass/Expression/_parser.pegjs', 'utf8'
parser = peg.buildParser parserSource
tests =
\"a.b.c\": {op:\"get\",args:[{op:\"get\",args:[{op:\"ref\",args:[\"a\"]},\"b\"]},\"c\"]}
\"a.1\": {op:\"get\",args:[{op:\"ref\",args:[\"a\"]},1]}
\"true\": true
\"false\": false
\"45.8\": 45.8
\"(45.8)\": 45.8
\"((45.8))\": 45.8
\"alpha\": {op:\"ref\",args:[\"alpha\"]}
\"35 + true * 2\": {op:\"+\", args:[35, {op:\"*\", args:[true,2]}]}
\" 5 * ( 2 + 2 ) \": {op:\"*\", args:[5, {op:\"+\", args:[2,2]}]}
\" ! ! true\": {op:\"!\",args:[{op:\"!\",args:[true]}]}
\"5 + -x\": {op:\"+\",args:[5,{op:\"-\",args:[{op:\"ref\",args:[\"x\"]}]}]}
\"true == 5 >= 2\": {op:\"==\",args:[true,{op:\">=\",args:[5,2]}]}
\"1 or 2 and 3\": {op:\"or\",args:[1,{op:\"and\",args:[2,3]}]}
\"1 ? 2 : 3\": {op:\"?:\",args:[1,2,3]}
\"1 ? 2 : 3 ? 4 : 5\" : {op:\"?:\",args:[1,2,{op:\"?:\",args:[3,4,5]}]}
\"a()(1,2)\" : {op:\"call\",args:[{op:\"call\",args:[{op:\"ref\",args:[\"a\"]},[]]},[1,2]]}
\"@\" : {op:\"this\"}
\"@foo\" : {op:\"get\",args:[{op:\"this\"},\"foo\"]}
'\"hello\"': \"hello\"
'\"\\\\t\\
\\
\\\\b\\\\\\\\foo\\\\\\/\"' : \"\\t
\\b\\\\foo\\/\"
\"[]\": {op:\"array\",args:[]}
\"[1,2]\": {op:\"array\",args:[1,2]}
\"[1+2]\": {op:\"array\",args:[{op:\"+\",args:[1,2]}]}
\"{}\": {op:\"object\",args:[]}
'{\"a\":2}': {op:\"object\",args:[[\"a\",2]]}
'{\"a\":2,\"b\":1+2}': {op:\"object\",args:[[\"a\",2],[\"b\",{op:\"+\",args:[1,2]}]]}
'@\"alpha\"': {op:\"get\",args:[{op:\"this\"},\"alpha\"]}
'*': {op:\"values\",args:[]}
'*.*': {op:\"values\",args:[{op:\"values\",args:[]}]}
\"foo.*\": {op:\"values\",args:[{op:\"ref\",args:[\"foo\"]}]}
\"..\": {op:\"ancestor\",args:[1]}
\"...\": {op:\"ancestor\",args:[2]}
\"@*{1+2}\": {op:\"eval\",args:[{op:\"values\",args:[{op:\"this\"}]},{op:\"+\",args:[1,2]}]}
\"/\": {op:\"root\"}
\"/foo\": {op:\"get\",args:[{op:\"root\"},\"foo\"]}
\"/*\": {op:\"values\",args:[{op:\"root\"}]}
for text, expected of tests
result = parser.parse text
if JSON.stringify(result) is JSON.stringify(expected)
console.log 'Pass: ' + text
else
console.log text, JSON.stringify result
return
",
input: "runtime\\glass\\Expression.coffee",
content: {
constructor: function(op, args) {
this.op = op;
if (args != null) {
this.args = args;
}
return this;
},
properties: {
op: {
type: "string",
name: "op",
writable: true
},
args: {
type: "array",
name: "args",
writable: true
}
},
test: function() {
var expected, fs, parser, parserSource, peg, result, tests, text;
return;
peg = require('pegjs');
fs = require('fs');
parserSource = fs.readFileSync('runtime/glass/Expression/_parser.pegjs', 'utf8');
parser = peg.buildParser(parserSource);
tests = {
"a.b.c": {
op: "get",
args: [{
op: "get",
args: [{
op: "ref",
args: ["a"]
},
"b"]
},
"c"]
},
"a.1": {
op: "get",
args: [{
op: "ref",
args: ["a"]
},
1]
},
"true": true,
"false": false,
"45.8": 45.8,
"(45.8)": 45.8,
"((45.8))": 45.8,
"alpha": {
op: "ref",
args: ["alpha"]
},
"35 + true * 2": {
op: "+",
args: [35, {
op: "*",
args: [true, 2]
}]
},
" 5 * ( 2 + 2 ) ": {
op: "*",
args: [5, {
op: "+",
args: [2, 2]
}]
},
" ! ! true": {
op: "!",
args: [{
op: "!",
args: [true]
}]
},
"5 + -x": {
op: "+",
args: [5, {
op: "-",
args: [{
op: "ref",
args: ["x"]
}]
}]
},
"true == 5 >= 2": {
op: "==",
args: [true, {
op: ">=",
args: [5, 2]
}]
},
"1 or 2 and 3": {
op: "or",
args: [1, {
op: "and",
args: [2, 3]
}]
},
"1 ? 2 : 3": {
op: "?:",
args: [1, 2, 3]
},
"1 ? 2 : 3 ? 4 : 5": {
op: "?:",
args: [1, 2, {
op: "?:",
args: [3, 4, 5]
}]
},
"a()(1,2)": {
op: "call",
args: [{
op: "call",
args: [{
op: "ref",
args: ["a"]
},
[]]
},
[1, 2]]
},
"@": {
op: "this"
},
"@foo": {
op: "get",
args: [{
op: "this"
},
"foo"]
},
'"hello"': "hello",
'"\\t
\\b\\\\foo\\\/"': "\t
\b\\foo\/",
"[]": {
op: "array",
args: []
},
"[1,2]": {
op: "array",
args: [1, 2]
},
"[1+2]": {
op: "array",
args: [{
op: "+",
args: [1, 2]
}]
},
"{}": {
op: "object",
args: []
},
'{"a":2}': {
op: "object",
args: [["a", 2]]
},
'{"a":2,"b":1+2}': {
op: "object",
args: [["a", 2], ["b", {
op: "+",
args: [1, 2]
}]]
},
'@"alpha"': {
op: "get",
args: [{
op: "this"
},
"alpha"]
},
'*': {
op: "values",
args: []
},
'*.*': {
op: "values",
args: [{
op: "values",
args: []
}]
},
"foo.*": {
op: "values",
args: [{
op: "ref",
args: ["foo"]
}]
},
"..": {
op: "ancestor",
args: [1]
},
"...": {
op: "ancestor",
args: [2]
},
"@*{1+2}": {
op: "eval",
args: [{
op: "values",
args: [{
op: "this"
}]
},
{
op: "+",
args: [1, 2]
}]
},
"/": {
op: "root"
},
"/foo": {
op: "get",
args: [{
op: "root"
},
"foo"]
},
"/*": {
op: "values",
args: [{
op: "root"
}]
}
};
for (text in tests) {
expected = tests[text];
result = parser.parse(text);
if (JSON.stringify(result) === JSON.stringify(expected)) {
console.log('Pass: ' + text);
} else {
console.log(text, JSON.stringify(result));
}
}
},
name: "Expression",
path: "glass.Expression",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.Expression._parser": "_parser",
"glass.values": "values"
},
implements: {
"glass.Expression": true
},
uri: "global:/glass/Expression"
}
},
"glass.JSONMergePatch": {
source: "
# applies a patch to the target object and returns the resulting target
apply: (target, patch) ->
if target? and target isnt patch and isPlainObject(patch) and not isPrimitive(target)
for key, value of patch
if value is undefined
delete target[key]
else
target[key] = apply target[key], patch[key]
return target
else
return patch
# (path1, path2, path3.., patch) ->
create: ->
if arguments.length is 1
return arguments[0]
result = {}
current = result
for arg, i in arguments when i + 1 < arguments.length
last = i + 2 is arguments.length
current = current[arg] = if last then arguments[arguments.length-1] else {}
result
test: ->
assertEquals {a:{b:12}}, create 'a', 'b', 12
assertEquals {a:3}, apply({a:1,b:2}, {a:3,b:undefined})
",
input: "runtime\\glass\\JSONMergePatch.coffee",
content: {
apply: function(target, patch) {
var key, value;
if ((target != null) && target !== patch && isPlainObject(patch) && !isPrimitive(target)) {
for (key in patch) {
value = patch[key];
if (value === void 0) {
delete target[key];
} else {
target[key] = apply(target[key], patch[key]);
}
}
return target;
} else {
return patch;
}
},
create: function() {
var arg, current, i, last, result, _i, _len;
if (arguments.length === 1) {
return arguments[0];
}
result = {};
current = result;
for (i = _i = 0, _len = arguments.length; _i < _len; i = ++_i) {
arg = arguments[i];
if (! (i + 1 < arguments.length)) {
continue;
}
last = i + 2 === arguments.length;
current = current[arg] = last ? arguments[arguments.length - 1] : {};
}
return result;
},
test: function() {
assertEquals({
a: {
b: 12
}
},
create('a', 'b', 12));
return assertEquals({
a: 3
},
apply({
a: 1,
b: 2
},
{
a: 3,
b: void 0
}));
},
name: "JSONMergePatch",
path: "glass.JSONMergePatch",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONMergePatch.apply": "apply",
"glass.JSONMergePatch.create": "create",
"glass.isPlainObject": "isPlainObject",
"glass.isPrimitive": "isPrimitive",
"glass.patch": "patch",
"glass.assertEquals": "assertEquals"
},
uri: "global:/glass/JSONMergePatch"
}
},
"glass.JSONPointer": {
source: "# json pointer implementation as per
# http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-05
_decodeStep: (step) -> step.replace(/~1/g, '/').replace(/~0/g, '~')
_getLastStep: (pointer) ->
_decodeStep pointer.substring(pointer.lastIndexOf('/') + 1)
_getParent: (pointer) ->
if not pointer?.length
null
else
pointer.substring(0, pointer.lastIndexOf('/'))
toArray: (pointer) ->
for step in pointer.substring(1).split('/')
_decodeStep step
get: (doc, pointer) ->
value = doc
if pointer.length
path = toArray pointer
for step in path when value?
value = value[step]
value
set: (doc, pointer, value) ->
parentPointer = _getParent pointer
if parentPointer?
parent = get doc, parentPointer
lastStep = _getLastStep pointer
parent[lastStep] = value
value
test: ->
assertEquals _getParent(\"/a/b/c\"), \"/a/b\"
assertEquals _getParent(\"/a\"), \"\"
assertEquals _getParent(\"\"), null
assertEquals _getLastStep(\"/a/b/c\"), \"c\"
assertEquals _getLastStep(\"/a~0~1\"), \"a~/\"
assertEquals _getLastStep(\"\"), \"\"
# tests as per spec
doc = {
\"foo\": [\"bar\", \"baz\"],
\"\": 0,
\"a/b\": 1,
\"c%d\": 2,
\"e^f\": 3,
\"g|h\": 4,
\"i\\\\j\": 5,
\"k\\\"l\": 6,
\" \": 7,
\"m~n\": 8
}
assertEquals get(doc, \"\"), doc
assertEquals get(doc, \"/foo\"), [\"bar\", \"baz\"]
assertEquals get(doc, \"/foo/0\"), \"bar\"
assertEquals get(doc, \"/\"), 0
assertEquals get(doc, \"/a~1b\"), 1
assertEquals get(doc, \"/c%d\"), 2
assertEquals get(doc, \"/e^f\"), 3
assertEquals get(doc, \"/g|h\"), 4
assertEquals get(doc, \"/i\\\\j\"), 5
assertEquals get(doc, \"/k\\\"l\"), 6
assertEquals get(doc, \"/ \"), 7
assertEquals get(doc, \"/m~0n\"), 8
# now test set
assertEquals set(doc, \"/\", 10), 10
assertEquals doc[\"\"], 10
assertEquals set(doc, \"/foo/0\", 10), 10
assertEquals doc.foo[0], 10",
input: "runtime\\glass\\JSONPointer.coffee",
content: {
toArray: function(pointer) {
var step, _i, _len, _ref, _results;
_ref = pointer.substring(1).split('/');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
step = _ref[_i];
_results.push(_decodeStep(step));
}
return _results;
},
get: function(doc, pointer) {
var path, step, value, _i, _len;
value = doc;
if (pointer.length) {
path = toArray(pointer);
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
}
return value;
},
set: function(doc, pointer, value) {
var lastStep, parent, parentPointer;
parentPointer = _getParent(pointer);
if (parentPointer != null) {
parent = get(doc, parentPointer);
lastStep = _getLastStep(pointer);
parent[lastStep] = value;
}
return value;
},
test: function() {
var doc;
assertEquals(_getParent("/a/b/c"), "/a/b");
assertEquals(_getParent("/a"), "");
assertEquals(_getParent(""), null);
assertEquals(_getLastStep("/a/b/c"), "c");
assertEquals(_getLastStep("/a~0~1"), "a~/");
assertEquals(_getLastStep(""), "");
doc = {
"foo": ["bar", "baz"],
"": 0,
"a/b": 1,
"c%d": 2,
"e^f": 3,
"g|h": 4,
"i\\j": 5,
"k\"l": 6,
" ": 7,
"m~n": 8
};
assertEquals(get(doc, ""), doc);
assertEquals(get(doc, "/foo"), ["bar", "baz"]);
assertEquals(get(doc, "/foo/0"), "bar");
assertEquals(get(doc, "/"), 0);
assertEquals(get(doc, "/a~1b"), 1);
assertEquals(get(doc, "/c%d"), 2);
assertEquals(get(doc, "/e^f"), 3);
assertEquals(get(doc, "/g|h"), 4);
assertEquals(get(doc, "/i\\j"), 5);
assertEquals(get(doc, "/k\"l"), 6);
assertEquals(get(doc, "/ "), 7);
assertEquals(get(doc, "/m~0n"), 8);
assertEquals(set(doc, "/", 10), 10);
assertEquals(doc[""], 10);
assertEquals(set(doc, "/foo/0", 10), 10);
return assertEquals(doc.foo[0], 10);
},
name: "JSONPointer",
path: "glass.JSONPointer",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONPointer._decodeStep": "_decodeStep",
"glass.JSONPointer._getLastStep": "_getLastStep",
"glass.JSONPointer._getParent": "_getParent",
"glass.JSONPointer.toArray": "toArray",
"glass.JSONPointer.get": "get",
"glass.JSONPointer.set": "set",
"glass.assertEquals": "assertEquals"
},
uri: "global:/glass/JSONPointer"
}
},
"glass.Observable": {
source: "properties:
is: (type) -> @constructor.implements[type.path ? type] is true
watchers:
serializable: false
watch: (property, watcher) ->
if isFunction property
watcher = property
property = ''
id = getId watcher
@patch 'watchers', property, id, watcher
# returns a function which will remove the watch
=> @patch 'watchers', property, getId(watcher), undefined
patch: (change) ->
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
try
JSONMergePatch.apply this, change
catch e
console.log e
finally
@notify change
return
notify: (change) ->
if @watchers?
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
for property, watchers of @watchers
if property.length is 0 or change.hasOwnProperty property
changeArg = if property.length is 0 then change else change[property]
for id, watcher of watchers
watcher this, changeArg
return
toJSON: ->
values =
class: @constructor.path
# serialize statically defined properties
for name, property of @constructor.properties
value = @[name]
if property.serializable isnt false and not isFunction(value)
values[name] = value
# serialize custom properties if allowed by schema
if @constructor.additionalProperties isnt false
for own name, value of @ when not isPrivate name
values[name] = value
values
toString: -> @toJSON()
test:
toJSON: ->
# I need this test later
# on a class that actually has serializable properties
a = new Observable
a.x = 12
a.y = ->
a.z = true
assertEquals a, {class:'glass.Observable', x:12,z:true}
watchAll: ->
# we should actually be able to watch ourselves get added to watchers
# this is very meta.
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch watcher
# now make sure we were called with our own watcher
assert watchArgs[0] is a
assert watchArgs[1]?.watchers?[\"\"]?
# reset watchArgs, and watch something else
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assertEquals a.a, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {a:{b:3}}
# now unwatch
unwatch()
# make sure universal watcher is now empty
assertEquals a.watchers[\"\"], {}
# now reset and do a new event, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
watchProperty: ->
# watch a property
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch \"foo\", watcher
# now make sure we were not called
assert watchArgs.length is 0
# reset watchArgs, and watch something else
a.patch \"foo\", \"b\", 3
assertEquals a.foo, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {b:3}
# now reset and do a different property, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
# now unwatch
unwatch()
# make sure we no longer see foo
watchArgs.length = 0
a.patch \"foo\", \"b\", 4
assert watchArgs.length is 0
",
input: "runtime\\glass\\Observable.coffee",
content: {
properties: {
is: {
value: function(type) {
var _ref;
return this.constructor["implements"][(_ref = type.path) != null ? _ref: type] === true;
},
name: "is"
},
watchers: {
serializable: false,
name: "watchers",
writable: true
},
watch: {
value: function(property, watcher) {
var id, _this = this;
if (isFunction(property)) {
watcher = property;
property = '';
}
id = getId(watcher);
this.patch('watchers', property, id, watcher);
return function() {
return _this.patch('watchers', property, getId(watcher), void 0);
};
},
name: "watch"
},
patch: {
value: function(change) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
try {
JSONMergePatch.apply(this, change);
} catch(e) {
console.log(e);
} finally {
this.notify(change);
}
},
name: "patch"
},
notify: {
value: function(change) {
var changeArg, id, property, watcher, watchers, _ref;
if (this.watchers != null) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
_ref = this.watchers;
for (property in _ref) {
watchers = _ref[property];
if (property.length === 0 || change.hasOwnProperty(property)) {
changeArg = property.length === 0 ? change: change[property];
for (id in watchers) {
watcher = watchers[id];
watcher(this, changeArg);
}
}
}
}
},
name: "notify"
},
toJSON: {
value: function() {
var name, property, value, values, _ref;
values = {
"class": this.constructor.path
};
_ref = this.constructor.properties;
for (name in _ref) {
property = _ref[name];
value = this[name];
if (property.serializable !== false && !isFunction(value)) {
values[name] = value;
}
}
if (this.constructor.additionalProperties !== false) {
for (name in this) {
if (!__hasProp.call(this, name)) continue;
value = this[name];
if (!isPrivate(name)) {
values[name] = value;
}
}
}
return values;
},
name: "toJSON"
},
toString: {
value: function() {
return this.toJSON();
},
name: "toString"
}
},
test: {
toJSON: function() {
var a;
a = new Observable;
a.x = 12;
a.y = function() {};
a.z = true;
return assertEquals(a, {
"class": 'glass.Observable',
x: 12,
z: true
});
},
watchAll: function() {
var a, unwatch, watchArgs, watcher, _ref, _ref1;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch(watcher);
assert(watchArgs[0] === a);
assert(((_ref = watchArgs[1]) != null ? (_ref1 = _ref.watchers) != null ? _ref1[""] : void 0 : void 0) != null);
watchArgs.length = 0;
a.patch("a", "b", 3);
assertEquals(a.a, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
a: {
b: 3
}
});
unwatch();
assertEquals(a.watchers[""], {});
watchArgs.length = 0;
a.patch("a", "b", 3);
return assert(watchArgs.length === 0);
},
watchProperty: function() {
var a, unwatch, watchArgs, watcher;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch("foo", watcher);
assert(watchArgs.length === 0);
a.patch("foo", "b", 3);
assertEquals(a.foo, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
b: 3
});
watchArgs.length = 0;
a.patch("a", "b", 3);
assert(watchArgs.length === 0);
unwatch();
watchArgs.length = 0;
a.patch("foo", "b", 4);
return assert(watchArgs.length === 0);
}
},
name: "Observable",
path: "glass.Observable",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONMergePatch": "JSONMergePatch",
"glass.isFunction": "isFunction",
"glass.isPrivate": "isPrivate",
"glass.values": "values",
"glass.patch": "patch",
"glass.assert": "assert",
"glass.assertEquals": "assertEquals",
"glass.getId": "getId"
},
implements: {
"glass.Observable": true
},
uri: "global:/glass/Observable"
}
},
"glass.Component": {
source: "extends: 'Observable'
constructor: (properties) ->
@patch properties
# now site ourselves on our parent
if @parent
id = getId @
patch @parent, id, @
@
properties:
id:
description: 'string which uniquely identifies this component within its parent'
type: 'string'
parent:
description: 'the object that contains this component'
serializable: false
type: 'object'
disposed: false
dispose: -> @patch 'disposed', true
notify: (change) ->
Observable.prototype.notify.apply this, arguments
if change?.disposed
# dispose of any disposable children
for id, child of @ when child?.parent is @
child.dispose?()
# remove self from parent
if @id and @parent
patch @parent, @id, undefined
return
test:
lifecycle: ->
parent = new Component
assert not parent.id?
assert not parent.parent?
child = new Component parent:parent
# id should be automatically assigned
assert isString child.id
assert parent is child.parent
assert parent[child.id] is child
assert parent.hasOwnProperty child.id
parent.dispose()
assert child.disposed is true
assert not parent.hasOwnProperty child.id
nonEnumerability: ->
visibleKeys = (key for key of new Component)
assertEquals visibleKeys, []",
input: "runtime\\glass\\Component.coffee",
content: {
extends: ["glass.Observable"],
constructor: function(properties) {
var id;
this.patch(properties);
if (this.parent) {
id = getId(this);
patch(this.parent, id, this);
}
return this;
},
properties: {
id: {
description: "string which uniquely identifies this component within its parent",
type: "string",
name: "id",
writable: true
},
parent: {
description: "the object that contains this component",
serializable: false,
type: "object",
name: "parent",
writable: true
},
disposed: {
value: false,
name: "disposed",
writable: true
},
dispose: {
value: function() {
return this.patch('disposed', true);
},
name: "dispose"
},
notify: {
value: function(change) {
var child, id;
Observable.prototype.notify.apply(this, arguments);
if (change != null ? change.disposed: void 0) {
for (id in this) {
child = this[id];
if ((child != null ? child.parent: void 0) === this) {
if (typeof child.dispose === "function") {
child.dispose();
}
}
}
if (this.id && this.parent) {
patch(this.parent, this.id, void 0);
}
}
},
name: "notify"
}
},
test: {
lifecycle: function() {
var child, parent;
parent = new Component;
assert(!(parent.id != null));
assert(!(parent.parent != null));
child = new Component({
parent: parent
});
assert(isString(child.id));
assert(parent === child.parent);
assert(parent[child.id] === child);
assert(parent.hasOwnProperty(child.id));
parent.dispose();
assert(child.disposed === true);
return assert(!parent.hasOwnProperty(child.id));
},
nonEnumerability: function() {
var key, visibleKeys;
visibleKeys = (function() {
var _results;
_results = [];
for (key in new Component) {
_results.push(key);
}
return _results;
})();
return assertEquals(visibleKeys, []);
}
},
name: "Component",
path: "glass.Component",
namespace: "glass",
require: {
glass: "glass",
"glass.Observable": "Observable"
},
import: {
"glass.Observable": "Observable",
"glass.isString": "isString",
"glass.patch": "patch",
"glass.assert": "assert",
"glass.assertEquals": "assertEquals",
"glass.getId": "getId"
},
implements: {
"glass.Component": true,
"glass.Observable": true
},
uri: "global:/glass/Component"
}
},
"glass.Container": {
source: "extends: 'Observable'
properties:
watch: ->
unwatch: ->
",
input: "runtime\\glass\\Container.coffee",
content: {
extends: ["glass.Observable"],
properties: {
watch: {
value: function() {},
name: "watch"
},
unwatch: {
value: function() {},
name: "unwatch"
}
},
name: "Container",
path: "glass.Container",
namespace: "glass",
require: {
glass: "glass",
"glass.Observable": "Observable"
},
import: {},
implements: {
"glass.Container": true,
"glass.Observable": true
},
uri: "global:/glass/Container"
}
},
"glass.Expression._parser": {
source: "{
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e,array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++)
array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
}
start = expression
expression = conditional
conditional = e:or args:(\"?\" b:expression \":\" c:expression {return [b,c];})* {
while (args.length > 0) {
e = expr(\"?:\", [e].concat(args.pop()));
}
return e;
}
or = a:and b:((\"or\") and)* { return joinLeft(a,b); }
and = a:equality b:((\"and\") equality)* { return joinLeft(a,b); }
equality = a:rel b:((\"==\" / \"!=\") rel)* { return joinLeft(a,b); }
rel = a:sum b:((\"<=\" / \">=\" / \"<\" / \">\") sum)* { return joinLeft(a,b); }
sum = a:product b:((\"+\" / \"-\") product)* { return joinLeft(a,b); }
product = a:not b:((\"*\" / \"div\" / \"mod\") not)* { return joinLeft(a,b); }
not = ops:(s op:(\"!\" / \"~\" / \"+\" / \"-\") { return op; })* b:primary { return unaryRight(ops,b); }
primary = s a:(group / literal / path) s { return a; }
group = \"(\" a:expression \")\" { return a; }
literal = s a:(boolean / number / string / array / object) s { return a; }
boolean = a:(\"true\" / \"false\") { return a == \"true\"; }
number = a:([0-9]+ (\".\" [0-9]+)?) { return parseFloat(toString(a)); }
hex = [a-fA-F0-9]
// as per JSON http://www.json.org
string = a:( '\"' (
[\\u0000-\\u0021\\u0023-\\u005c\\u005e-\\uffff] // all unicode chars except \\ and \"
/ (\"\\\\\" (\"\\\"\" / \"\\\\\" / \"\\/\" / \"b\" / \"f\" / \"n\" / \"r\" / \"t\" / (\"u\" hex hex hex hex)))
)* '\"' )
{ return JSON.parse(toString(a)); }
array = \"[\" a:values \"]\" { return expr(\"array\", a); }
values = first:expression? args:(\",\" b:expression {return b;})* {
if (first != \"\") { args.unshift(first); } return args;
}
object = \"{\" a:keyvalues \"}\" { return expr(\"object\", a); }
keyvalue = s a:string s \":\" b:expression { return [a,b]; }
keyvalues = first:keyvalue? rest:(\",\" b:keyvalue {return b;})* {
if (first) { rest.unshift(first); } return rest;
}
ref = a:(\"//\" / \"/\" / \"$\" / \"**\" / \"*\" / \"..\" / \".\") b:slashProperty? {
e = expr(a); if (b) { b.args.unshift(e); e = b; } return e;
}
/ a:id { return expr(\"ref\", [a]); }
id = a:[a-z_]+ b:[a-z_0-9]* { return a.join('') + b.join(''); }
property = \"/\" a:slashProperty { return a; }
/ \"{\" a:expression \"}\" { return expr(\"{}\", [a]); } // locally scoped expression
/ \"[\" a:expression \"]\" { return expr(\"[]\", [a]); } // predicate
slashProperty = a:(id/number/string) { return expr(\"/\", [a]); }
/ a:(\"..\" / \"*\") { return expr(a, []); }
s \"space\" = [ ]* { return ''; }
path = a:root b:step* {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
}
root = a:implicitDotRoot b:dotStep? { return joinPath(a,b); }
/ explicitDotRoot
step = \".\" a:dotStep { return a; }
/ noDotStep
implicitDotRoot = \"/\" { return expr(\"root\"); }
/ \"@\" { return expr(\"this\"); }
/ \".\" a:\".\"+ { return expr(\"ancestor\", [a.length]); }
explicitDotRoot = a:id { return expr(\"ref\", [a]); }
/ \"*\" { return expr(\"values\", []); }
dotStep = a:(id / string / number) { return expr(\"get\", [a]); }
/ \"*\" { return expr(\"values\", []); }
noDotStep = \"{\" a:expression \"}\" { return expr(\"eval\", [a]); }
/ \"[\" a:expression \"]\" { return expr(\"pred\", [a]); }
/ \"(\" a:values \")\" { return expr(\"call\", [a]); }
",
input: "runtime\\glass\\Expression\\_parser.pegjs",
content: {
value: {
parse: function(input, startRule) {
var parseFunctions = {
"conditional": parse_conditional,
"or": parse_or,
"and": parse_and,
"equality": parse_equality,
"rel": parse_rel,
"sum": parse_sum,
"product": parse_product,
"not": parse_not,
"primary": parse_primary,
"group": parse_group,
"literal": parse_literal,
"boolean": parse_boolean,
"number": parse_number,
"hex": parse_hex,
"string": parse_string,
"array": parse_array,
"values": parse_values,
"object": parse_object,
"keyvalue": parse_keyvalue,
"keyvalues": parse_keyvalues,
"ref": parse_ref,
"id": parse_id,
"property": parse_property,
"slashProperty": parse_slashProperty,
"s": parse_s,
"path": parse_path,
"root": parse_root,
"step": parse_step,
"implicitDotRoot": parse_implicitDotRoot,
"explicitDotRoot": parse_explicitDotRoot,
"dotStep": parse_dotStep,
"noDotStep": parse_noDotStep
};
if (startRule !== undefined) {
if (parseFunctions[startRule] === undefined) {
throw new Error("Invalid rule name: " + quote(startRule) + ".");
}
} else {
startRule = "conditional";
}
var pos = 0;
var reportFailures = 0;
var rightmostFailuresPos = 0;
var rightmostFailuresExpected = [];
function padLeft(input, padding, length) {
var result = input;
var padLength = length - input.length;
for (var i = 0; i < padLength; i++) {
result = padding + result;
}
return result;
}
function escape(ch) {
var charCode = ch.charCodeAt(0);
var escapeChar;
var length;
if (charCode <= 0xFF) {
escapeChar = 'x';
length = 2;
} else {
escapeChar = 'u';
length = 4;
}
return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
}
function matchFailed(failure) {
if (pos < rightmostFailuresPos) {
return;
}
if (pos > rightmostFailuresPos) {
rightmostFailuresPos = pos;
rightmostFailuresExpected = [];
}
rightmostFailuresExpected.push(failure);
}
function parse_conditional() {
var result0, result1, result2, result3, result4, result5;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_or();
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, e, args) {
while (args.length > 0) {
e = expr("?:", [e].concat(args.pop()));
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_or() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_and();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_and() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_equality();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_equality() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_rel();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_rel() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_sum();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_sum() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_product();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_product() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_not();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_not() {
var result0, result1, result2;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = [];
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
while (result1 !== null) {
result0.push(result1);
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
}
if (result0 !== null) {
result1 = parse_primary();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, ops, b) {
return unaryRight(ops, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_primary() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_group();
if (result1 === null) {
result1 = parse_literal();
if (result1 === null) {
result1 = parse_path();
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_group() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_literal() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_boolean();
if (result1 === null) {
result1 = parse_number();
if (result1 === null) {
result1 = parse_string();
if (result1 === null) {
result1 = parse_array();
if (result1 === null) {
result1 = parse_object();
}
}
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_boolean() {
var result0;
var pos0;
pos0 = pos;
if (input.substr(pos, 4) === "true") {
result0 = "true";
pos += 4;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"true\"");
}
}
if (result0 === null) {
if (input.substr(pos, 5) === "false") {
result0 = "false";
pos += 5;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"false\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a == "true";
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_number() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
pos2 = pos;
if (input.charCodeAt(pos) === 46) {
result1 = ".";
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result1 !== null) {
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result3 !== null) {
result2 = [];
while (result3 !== null) {
result2.push(result3);
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result2 = null;
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos2;
}
} else {
result1 = null;
pos = pos2;
}
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return parseFloat(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_hex() {
var result0;
if (/^[a-fA-F0-9]/.test(input.charAt(pos))) {
result0 = input.charAt(pos);
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("[a-fA-F0-9]");
}
}
return result0;
}
function parse_string() {
var result0, result1, result2, result3, result4, result5, result6, result7;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 34) {
result0 = "\"";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result0 !== null) {
result1 = [];
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
}
if (result1 !== null) {
if (input.charCodeAt(pos) === 34) {
result2 = "\"";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return JSON.parse(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_array() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("array", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_values() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_conditional();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, args) {
if (first != "") {
args.unshift(first);
}
return args;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_object() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_keyvalues();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("object", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalue() {
var result0, result1, result2, result3, result4;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_string();
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
if (input.charCodeAt(pos) === 58) {
result3 = ":";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result3 !== null) {
result4 = parse_conditional();
if (result4 !== null) {
result0 = [result0, result1, result2, result3, result4];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return [a, b];
})(pos0, result0[1], result0[4]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalues() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_keyvalue();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, rest) {
if (first) {
rest.unshift(first);
}
return rest;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_ref() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.substr(pos, 2) === "//") {
result0 = "//";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"//\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 36) {
result0 = "$";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"$\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "**") {
result0 = "**";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"**\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
}
}
}
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
e = expr(a);
if (b) {
b.args.unshift(e);
e = b;
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_id() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
result1 = [];
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return a.join('') + b.join('');
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_property() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("{}", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("[]", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_slashProperty() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_number();
if (result0 === null) {
result0 = parse_string();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("/", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(a, []);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_s() {
var result0, result1;
var pos0;
reportFailures++;
pos0 = pos;
result0 = [];
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
while (result1 !== null) {
result0.push(result1);
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
}
if (result0 !== null) {
result0 = (function(offset) {
return '';
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
reportFailures--;
if (reportFailures === 0 && result0 === null) {
matchFailed("space");
}
return result0;
}
function parse_path() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_root();
if (result0 !== null) {
result1 = [];
result2 = parse_step();
while (result2 !== null) {
result1.push(result2);
result2 = parse_step();
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_root() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_implicitDotRoot();
if (result0 !== null) {
result1 = parse_dotStep();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinPath(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_explicitDotRoot();
}
return result0;
}
function parse_step() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
result1 = parse_dotStep();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_noDotStep();
}
return result0;
}
function parse_implicitDotRoot() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("root");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 64) {
result0 = "@";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"@\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("this");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result2 !== null) {
result1 = [];
while (result2 !== null) {
result1.push(result2);
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
} else {
result1 = null;
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ancestor", [a.length]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_explicitDotRoot() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_dotStep() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_string();
if (result0 === null) {
result0 = parse_number();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("get", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_noDotStep() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("eval", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("pred", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("call", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function cleanupExpected(expected) {
expected.sort();
var lastExpected = null;
var cleanExpected = [];
for (var i = 0; i < expected.length; i++) {
if (expected[i] !== lastExpected) {
cleanExpected.push(expected[i]);
lastExpected = expected[i];
}
}
return cleanExpected;
}
function computeErrorPosition() {
/*
* The first idea was to use |String.split| to break the input up to the
* error position along newlines and derive the line and column from
* there. However IE's |split| implementation is so broken that it was
* enough to prevent it.
*/
var line = 1;
var column = 1;
var seenCR = false;
for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
var ch = input.charAt(i);
if (ch === "
") {
if (!seenCR) {
line++;
}
column = 1;
seenCR = false;
} else if (ch === "
" || ch === "\u2028" || ch === "\u2029") {
line++;
column = 1;
seenCR = true;
} else {
column++;
seenCR = false;
}
}
return {
line: line,
column: column
};
}
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e, array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++) array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
var result = parseFunctions[startRule]();
/*
* The parser is now in one of the following three states:
*
* 1. The parser successfully parsed the whole input.
*
* - |result !== null|
* - |pos === input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 2. The parser successfully parsed only a part of the input.
*
* - |result !== null|
* - |pos < input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 3. The parser did not successfully parse any part of the input.
*
* - |result === null|
* - |pos === 0|
* - |rightmostFailuresExpected| contains at least one failure
*
* All code following this comment (including called functions) must
* handle these states.
*/
if (result === null || pos !== input.length) {
var offset = Math.max(pos, rightmostFailuresPos);
var found = offset < input.length ? input.charAt(offset) : null;
var errorPosition = computeErrorPosition();
throw new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column);
}
return result;
},
toSource: function() {
return this._source;
},
SyntaxError: function(expected, found, offset, line, column) {
function buildMessage(expected, found) {
var expectedHumanized, foundHumanized;
switch (expected.length) {
case 0:
expectedHumanized = "end of input";
break;
case 1:
expectedHumanized = expected[0];
break;
default:
expectedHumanized = expected.slice(0, expected.length - 1).join(", ") + " or " + expected[expected.length - 1];
}
foundHumanized = found ? quote(found) : "end of input";
return "Expected " + expectedHumanized + " but " + foundHumanized + " found.";
}
this.name = "SyntaxError";
this.expected = expected;
this.found = found;
this.message = buildMessage(expected, found);
this.offset = offset;
this.line = line;
this.column = column;
}
},
name: "_parser",
path: "glass.Expression._parser",
namespace: "glass.Expression",
require: {
"glass.Expression": "Expression"
},
import: {
"glass.values": "values"
},
uri: "global:/glass/Expression/_parser"
}
}
}
} | {
options: {
input: {
dir: "runtime",
match: /\.(coffee|pegjs)$/
},
output: {
dir: "www/js"
},
script: {
includes: "www/includes.html",
prefix: "/js/"
},
module: {
main: "glass.js",
prefix: "./www/js/"
},
debug: "buildlog.html",
test: "glass.allTests",
addon: {
pregenerate: {
addUri: function(schema) {
var content, type, typeName, _ref2, _ref3;
_ref2 = schema.types;
for (typeName in _ref2) {
type = _ref2[typeName];
content = type.content;
if (content.extension) {
continue;
}
if ((_ref3 = content.uri) == null) {
content.uri = "global:/" + (content.path.replace(/\./g, '/'));
}
}
return schema;
}
}
},
namespace: ""
},
types: {
String: {
source: "extension: true
properties:
\tstartsWith: (s) -> @slice(0,s.length) is s
\tendsWith: (s) -> @slice(-s.length) is s
\tcontains: (s) -> @indexOf(s) >= 0
\ttoArray: () -> @split ''",
input: "runtime\\String.coffee",
content: {
extension: true,
properties: {
startsWith: {
value: function(s) {
return this.slice(0, s.length) === s;
},
name: "startsWith"
},
endsWith: {
value: function(s) {
return this.slice( - s.length) === s;
},
name: "endsWith"
},
contains: {
value: function(s) {
return this.indexOf(s) >= 0;
},
name: "contains"
},
toArray: {
value: function() {
return this.split('');
},
name: "toArray"
}
},
name: "String",
path: "String",
namespace: "",
require: {},
import: {},
implements: {
String: true
}
}
},
glass: {
source: "require:
\tString: true
# runtime type tests
isFunction: (object) -> object? and typeof object is 'function'
isString: (object) -> object?.constructor is String
isArray: (object) -> Array.isArray object
isBoolean: (object) -> object? and typeof object is 'boolean'
isNumber: (object) -> object? and typeof object is 'number'
isObject: (object) -> typeof object is 'object'
isPlainObject: (object) -> object?.constructor is Object
isPrototype: (object) -> object? and object is object.constructor.prototype
isDate: (object) -> object?.constructor is Date
isPrimitive: (object) -> isString(object) or isBoolean(object) or isNumber(object) or isDate(object)
isPrivate: (property) -> property?[0] is '_'
# generic utility functions
values: (object) -> (value for key, value of object)
# generic patch method, uses patch method built into object if present
patch: (target, pathAndPatch...) ->
patch = JSONMergePatch.create.apply null, pathAndPatch
if isFunction target?.patch
target.patch patch
else
glass.JSONMergePatch.apply target, patch
# testing assertions
_getStackLocationInfo: (e, depth) ->
line = e.stack?.split('
')[depth]
return null unless line?
match = /\\(([\\w\\W]*?):(\\d+):(\\d+)\\)/.exec line
return {
file: match[1]
line: parseInt match[2]
column: parseInt match[3]
}
_throwAssertionFailure: (message) ->
try
throw new Error \"Assertion failed: \" + message
catch e
info = _getStackLocationInfo e, 3
if info?
_dumpFile info.file, info.line - 2, info.line + 2, info.line
throw e
_dumpFile: (file, from=1, to, highlight) ->
fs = require 'fs'
return unless fs?
try
content = fs.readFileSync(file).toString()
catch e
content = \"Source not found: #{e}\"
console.log '------------------------------------------------'
console.log file
console.log '------------------------------------------------'
number = 1
if content?
lines = content.split /
|
/
to ?= lines.length
for line in lines
lineNumber = number++
if lineNumber >= from and lineNumber <= to
num = String lineNumber
while num.length < 3
num += ' '
if lineNumber is highlight
`console.log(\"\\033[91m\" + num + \": \" + line + \"\\033[0m\");`
else
`console.log(num + \": \" + line);`
console.log '------------------------------------------------'
assert: (a) ->
_throwAssertionFailure JSON.stringify(a) unless a
assertTrue: (a) ->
_throwAssertionFailure JSON.stringify(a) + \" != true\" unless a is true
assertEquals: (a, b) ->
if JSON.stringify(a) isnt JSON.stringify(b)
_throwAssertionFailure JSON.stringify(a) + ' != ' + JSON.stringify(b)
# gets a unique string identifier for any object
getId:
do: ->
counter = 0
(a) ->
if a is null
return '__null__'
if a is undefined
return '__undefined__'
if typeof a is 'object' or typeof a is 'function'
return a.id ?= '__' + (counter++) + '__'
# 12 == \"12\" under this technique
return a.toString()
getType: (path) ->
array = if isArray path then path else path.split '.'
value = global
for step in path when value?
value = value[step]
throw new Error \"Type not found: #{path}\" unless isFunction value
value
test:
values: ->
assertEquals values({a:1,b:3,c:2}), [1,3,2]
patch: ->
x = {a:{foo:1,bar:3},b:2}
patch x, 'a', 'foo', 5
assertEquals x.a.foo, 5
",
input: "runtime\\glass.coffee",
content: {
require: {
String: "String"
},
isFunction: function(object) {
return (object != null) && typeof object === 'function';
},
isString: function(object) {
return (object != null ? object.constructor: void 0) === String;
},
isArray: function(object) {
return Array.isArray(object);
},
isBoolean: function(object) {
return (object != null) && typeof object === 'boolean';
},
isNumber: function(object) {
return (object != null) && typeof object === 'number';
},
isObject: function(object) {
return typeof object === 'object';
},
isPlainObject: function(object) {
return (object != null ? object.constructor: void 0) === Object;
},
isPrototype: function(object) {
return (object != null) && object === object.constructor.prototype;
},
isDate: function(object) {
return (object != null ? object.constructor: void 0) === Date;
},
isPrimitive: function(object) {
return isString(object) || isBoolean(object) || isNumber(object) || isDate(object);
},
isPrivate: function(property) {
return (property != null ? property[0] : void 0) === '_';
},
values: function(object) {
var key, value, _results;
_results = [];
for (key in object) {
value = object[key];
_results.push(value);
}
return _results;
},
patch: function() {
var patch, pathAndPatch, target;
target = arguments[0],
pathAndPatch = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
patch = JSONMergePatch.create.apply(null, pathAndPatch);
if (isFunction(target != null ? target.patch: void 0)) {
return target.patch(patch);
} else {
return glass.JSONMergePatch.apply(target, patch);
}
},
assert: function(a) {
if (!a) {
return _throwAssertionFailure(JSON.stringify(a));
}
},
assertTrue: function(a) {
if (a !== true) {
return _throwAssertionFailure(JSON.stringify(a) + " != true");
}
},
assertEquals: function(a, b) {
if (JSON.stringify(a) !== JSON.stringify(b)) {
return _throwAssertionFailure(JSON.stringify(a) + ' != ' + JSON.stringify(b));
}
},
getId: {
do: function() {
var counter;
counter = 0;
return function(a) {
var _ref;
if (a === null) {
return '__null__';
}
if (a === void 0) {
return '__undefined__';
}
if (typeof a === 'object' || typeof a === 'function') {
return (_ref = a.id) != null ? _ref: a.id = '__' + (counter++) + '__';
}
return a.toString();
};
}
},
getType: function(path) {
var array, step, value, _i, _len;
array = isArray(path) ? path: path.split('.');
value = global;
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
if (!isFunction(value)) {
throw new Error("Type not found: " + path);
}
return value;
},
test: {
values: function() {
return assertEquals(values({
a: 1,
b: 3,
c: 2
}), [1, 3, 2]);
},
patch: function() {
var x;
x = {
a: {
foo: 1,
bar: 3
},
b: 2
};
patch(x, 'a', 'foo', 5);
return assertEquals(x.a.foo, 5);
}
},
name: "glass",
path: "glass",
namespace: "",
import: {
"glass.JSONMergePatch": "JSONMergePatch",
"glass.isFunction": "isFunction",
"glass.isString": "isString",
"glass.isArray": "isArray",
"glass.isBoolean": "isBoolean",
"glass.isNumber": "isNumber",
"glass.isDate": "isDate",
"glass.values": "values",
"glass.patch": "patch",
"glass._getStackLocationInfo": "_getStackLocationInfo",
"glass._throwAssertionFailure": "_throwAssertionFailure",
"glass._dumpFile": "_dumpFile",
"glass.assertEquals": "assertEquals"
},
uri: "global:/glass"
}
},
"glass.Expression": {
source: "constructor: (op, args) ->
@op = op
@args = args if args?
@
properties:
op:
type: 'string'
args:
type: 'array'
test: ->
return
peg = require 'pegjs'
fs = require 'fs'
parserSource = fs.readFileSync 'runtime/glass/Expression/_parser.pegjs', 'utf8'
parser = peg.buildParser parserSource
tests =
\"a.b.c\": {op:\"get\",args:[{op:\"get\",args:[{op:\"ref\",args:[\"a\"]},\"b\"]},\"c\"]}
\"a.1\": {op:\"get\",args:[{op:\"ref\",args:[\"a\"]},1]}
\"true\": true
\"false\": false
\"45.8\": 45.8
\"(45.8)\": 45.8
\"((45.8))\": 45.8
\"alpha\": {op:\"ref\",args:[\"alpha\"]}
\"35 + true * 2\": {op:\"+\", args:[35, {op:\"*\", args:[true,2]}]}
\" 5 * ( 2 + 2 ) \": {op:\"*\", args:[5, {op:\"+\", args:[2,2]}]}
\" ! ! true\": {op:\"!\",args:[{op:\"!\",args:[true]}]}
\"5 + -x\": {op:\"+\",args:[5,{op:\"-\",args:[{op:\"ref\",args:[\"x\"]}]}]}
\"true == 5 >= 2\": {op:\"==\",args:[true,{op:\">=\",args:[5,2]}]}
\"1 or 2 and 3\": {op:\"or\",args:[1,{op:\"and\",args:[2,3]}]}
\"1 ? 2 : 3\": {op:\"?:\",args:[1,2,3]}
\"1 ? 2 : 3 ? 4 : 5\" : {op:\"?:\",args:[1,2,{op:\"?:\",args:[3,4,5]}]}
\"a()(1,2)\" : {op:\"call\",args:[{op:\"call\",args:[{op:\"ref\",args:[\"a\"]},[]]},[1,2]]}
\"@\" : {op:\"this\"}
\"@foo\" : {op:\"get\",args:[{op:\"this\"},\"foo\"]}
'\"hello\"': \"hello\"
'\"\\\\t\\
\\
\\\\b\\\\\\\\foo\\\\\\/\"' : \"\\t
\\b\\\\foo\\/\"
\"[]\": {op:\"array\",args:[]}
\"[1,2]\": {op:\"array\",args:[1,2]}
\"[1+2]\": {op:\"array\",args:[{op:\"+\",args:[1,2]}]}
\"{}\": {op:\"object\",args:[]}
'{\"a\":2}': {op:\"object\",args:[[\"a\",2]]}
'{\"a\":2,\"b\":1+2}': {op:\"object\",args:[[\"a\",2],[\"b\",{op:\"+\",args:[1,2]}]]}
'@\"alpha\"': {op:\"get\",args:[{op:\"this\"},\"alpha\"]}
'*': {op:\"values\",args:[]}
'*.*': {op:\"values\",args:[{op:\"values\",args:[]}]}
\"foo.*\": {op:\"values\",args:[{op:\"ref\",args:[\"foo\"]}]}
\"..\": {op:\"ancestor\",args:[1]}
\"...\": {op:\"ancestor\",args:[2]}
\"@*{1+2}\": {op:\"eval\",args:[{op:\"values\",args:[{op:\"this\"}]},{op:\"+\",args:[1,2]}]}
\"/\": {op:\"root\"}
\"/foo\": {op:\"get\",args:[{op:\"root\"},\"foo\"]}
\"/*\": {op:\"values\",args:[{op:\"root\"}]}
for text, expected of tests
result = parser.parse text
if JSON.stringify(result) is JSON.stringify(expected)
console.log 'Pass: ' + text
else
console.log text, JSON.stringify result
return
",
input: "runtime\\glass\\Expression.coffee",
content: {
constructor: function(op, args) {
this.op = op;
if (args != null) {
this.args = args;
}
return this;
},
properties: {
op: {
type: "string",
name: "op",
writable: true
},
args: {
type: "array",
name: "args",
writable: true
}
},
test: function() {
var expected, fs, parser, parserSource, peg, result, tests, text;
return;
peg = require('pegjs');
fs = require('fs');
parserSource = fs.readFileSync('runtime/glass/Expression/_parser.pegjs', 'utf8');
parser = peg.buildParser(parserSource);
tests = {
"a.b.c": {
op: "get",
args: [{
op: "get",
args: [{
op: "ref",
args: ["a"]
},
"b"]
},
"c"]
},
"a.1": {
op: "get",
args: [{
op: "ref",
args: ["a"]
},
1]
},
"true": true,
"false": false,
"45.8": 45.8,
"(45.8)": 45.8,
"((45.8))": 45.8,
"alpha": {
op: "ref",
args: ["alpha"]
},
"35 + true * 2": {
op: "+",
args: [35, {
op: "*",
args: [true, 2]
}]
},
" 5 * ( 2 + 2 ) ": {
op: "*",
args: [5, {
op: "+",
args: [2, 2]
}]
},
" ! ! true": {
op: "!",
args: [{
op: "!",
args: [true]
}]
},
"5 + -x": {
op: "+",
args: [5, {
op: "-",
args: [{
op: "ref",
args: ["x"]
}]
}]
},
"true == 5 >= 2": {
op: "==",
args: [true, {
op: ">=",
args: [5, 2]
}]
},
"1 or 2 and 3": {
op: "or",
args: [1, {
op: "and",
args: [2, 3]
}]
},
"1 ? 2 : 3": {
op: "?:",
args: [1, 2, 3]
},
"1 ? 2 : 3 ? 4 : 5": {
op: "?:",
args: [1, 2, {
op: "?:",
args: [3, 4, 5]
}]
},
"a()(1,2)": {
op: "call",
args: [{
op: "call",
args: [{
op: "ref",
args: ["a"]
},
[]]
},
[1, 2]]
},
"@": {
op: "this"
},
"@foo": {
op: "get",
args: [{
op: "this"
},
"foo"]
},
'"hello"': "hello",
'"\\t
\\b\\\\foo\\\/"': "\t
\b\\foo\/",
"[]": {
op: "array",
args: []
},
"[1,2]": {
op: "array",
args: [1, 2]
},
"[1+2]": {
op: "array",
args: [{
op: "+",
args: [1, 2]
}]
},
"{}": {
op: "object",
args: []
},
'{"a":2}': {
op: "object",
args: [["a", 2]]
},
'{"a":2,"b":1+2}': {
op: "object",
args: [["a", 2], ["b", {
op: "+",
args: [1, 2]
}]]
},
'@"alpha"': {
op: "get",
args: [{
op: "this"
},
"alpha"]
},
'*': {
op: "values",
args: []
},
'*.*': {
op: "values",
args: [{
op: "values",
args: []
}]
},
"foo.*": {
op: "values",
args: [{
op: "ref",
args: ["foo"]
}]
},
"..": {
op: "ancestor",
args: [1]
},
"...": {
op: "ancestor",
args: [2]
},
"@*{1+2}": {
op: "eval",
args: [{
op: "values",
args: [{
op: "this"
}]
},
{
op: "+",
args: [1, 2]
}]
},
"/": {
op: "root"
},
"/foo": {
op: "get",
args: [{
op: "root"
},
"foo"]
},
"/*": {
op: "values",
args: [{
op: "root"
}]
}
};
for (text in tests) {
expected = tests[text];
result = parser.parse(text);
if (JSON.stringify(result) === JSON.stringify(expected)) {
console.log('Pass: ' + text);
} else {
console.log(text, JSON.stringify(result));
}
}
},
name: "Expression",
path: "glass.Expression",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.Expression._parser": "_parser",
"glass.values": "values"
},
implements: {
"glass.Expression": true
},
uri: "global:/glass/Expression"
}
},
"glass.JSONMergePatch": {
source: "
# applies a patch to the target object and returns the resulting target
apply: (target, patch) ->
if target? and target isnt patch and isPlainObject(patch) and not isPrimitive(target)
for key, value of patch
if value is undefined
delete target[key]
else
target[key] = apply target[key], patch[key]
return target
else
return patch
# (path1, path2, path3.., patch) ->
create: ->
if arguments.length is 1
return arguments[0]
result = {}
current = result
for arg, i in arguments when i + 1 < arguments.length
last = i + 2 is arguments.length
current = current[arg] = if last then arguments[arguments.length-1] else {}
result
test: ->
assertEquals {a:{b:12}}, create 'a', 'b', 12
assertEquals {a:3}, apply({a:1,b:2}, {a:3,b:undefined})
",
input: "runtime\\glass\\JSONMergePatch.coffee",
content: {
apply: function(target, patch) {
var key, value;
if ((target != null) && target !== patch && isPlainObject(patch) && !isPrimitive(target)) {
for (key in patch) {
value = patch[key];
if (value === void 0) {
delete target[key];
} else {
target[key] = apply(target[key], patch[key]);
}
}
return target;
} else {
return patch;
}
},
create: function() {
var arg, current, i, last, result, _i, _len;
if (arguments.length === 1) {
return arguments[0];
}
result = {};
current = result;
for (i = _i = 0, _len = arguments.length; _i < _len; i = ++_i) {
arg = arguments[i];
if (! (i + 1 < arguments.length)) {
continue;
}
last = i + 2 === arguments.length;
current = current[arg] = last ? arguments[arguments.length - 1] : {};
}
return result;
},
test: function() {
assertEquals({
a: {
b: 12
}
},
create('a', 'b', 12));
return assertEquals({
a: 3
},
apply({
a: 1,
b: 2
},
{
a: 3,
b: void 0
}));
},
name: "JSONMergePatch",
path: "glass.JSONMergePatch",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONMergePatch.apply": "apply",
"glass.JSONMergePatch.create": "create",
"glass.isPlainObject": "isPlainObject",
"glass.isPrimitive": "isPrimitive",
"glass.patch": "patch",
"glass.assertEquals": "assertEquals"
},
uri: "global:/glass/JSONMergePatch"
}
},
"glass.JSONPointer": {
source: "# json pointer implementation as per
# http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-05
_decodeStep: (step) -> step.replace(/~1/g, '/').replace(/~0/g, '~')
_getLastStep: (pointer) ->
_decodeStep pointer.substring(pointer.lastIndexOf('/') + 1)
_getParent: (pointer) ->
if not pointer?.length
null
else
pointer.substring(0, pointer.lastIndexOf('/'))
toArray: (pointer) ->
for step in pointer.substring(1).split('/')
_decodeStep step
get: (doc, pointer) ->
value = doc
if pointer.length
path = toArray pointer
for step in path when value?
value = value[step]
value
set: (doc, pointer, value) ->
parentPointer = _getParent pointer
if parentPointer?
parent = get doc, parentPointer
lastStep = _getLastStep pointer
parent[lastStep] = value
value
test: ->
assertEquals _getParent(\"/a/b/c\"), \"/a/b\"
assertEquals _getParent(\"/a\"), \"\"
assertEquals _getParent(\"\"), null
assertEquals _getLastStep(\"/a/b/c\"), \"c\"
assertEquals _getLastStep(\"/a~0~1\"), \"a~/\"
assertEquals _getLastStep(\"\"), \"\"
# tests as per spec
doc = {
\"foo\": [\"bar\", \"baz\"],
\"\": 0,
\"a/b\": 1,
\"c%d\": 2,
\"e^f\": 3,
\"g|h\": 4,
\"i\\\\j\": 5,
\"k\\\"l\": 6,
\" \": 7,
\"m~n\": 8
}
assertEquals get(doc, \"\"), doc
assertEquals get(doc, \"/foo\"), [\"bar\", \"baz\"]
assertEquals get(doc, \"/foo/0\"), \"bar\"
assertEquals get(doc, \"/\"), 0
assertEquals get(doc, \"/a~1b\"), 1
assertEquals get(doc, \"/c%d\"), 2
assertEquals get(doc, \"/e^f\"), 3
assertEquals get(doc, \"/g|h\"), 4
assertEquals get(doc, \"/i\\\\j\"), 5
assertEquals get(doc, \"/k\\\"l\"), 6
assertEquals get(doc, \"/ \"), 7
assertEquals get(doc, \"/m~0n\"), 8
# now test set
assertEquals set(doc, \"/\", 10), 10
assertEquals doc[\"\"], 10
assertEquals set(doc, \"/foo/0\", 10), 10
assertEquals doc.foo[0], 10",
input: "runtime\\glass\\JSONPointer.coffee",
content: {
toArray: function(pointer) {
var step, _i, _len, _ref, _results;
_ref = pointer.substring(1).split('/');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
step = _ref[_i];
_results.push(_decodeStep(step));
}
return _results;
},
get: function(doc, pointer) {
var path, step, value, _i, _len;
value = doc;
if (pointer.length) {
path = toArray(pointer);
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
}
return value;
},
set: function(doc, pointer, value) {
var lastStep, parent, parentPointer;
parentPointer = _getParent(pointer);
if (parentPointer != null) {
parent = get(doc, parentPointer);
lastStep = _getLastStep(pointer);
parent[lastStep] = value;
}
return value;
},
test: function() {
var doc;
assertEquals(_getParent("/a/b/c"), "/a/b");
assertEquals(_getParent("/a"), "");
assertEquals(_getParent(""), null);
assertEquals(_getLastStep("/a/b/c"), "c");
assertEquals(_getLastStep("/a~0~1"), "a~/");
assertEquals(_getLastStep(""), "");
doc = {
"foo": ["bar", "baz"],
"": 0,
"a/b": 1,
"c%d": 2,
"e^f": 3,
"g|h": 4,
"i\\j": 5,
"k\"l": 6,
" ": 7,
"m~n": 8
};
assertEquals(get(doc, ""), doc);
assertEquals(get(doc, "/foo"), ["bar", "baz"]);
assertEquals(get(doc, "/foo/0"), "bar");
assertEquals(get(doc, "/"), 0);
assertEquals(get(doc, "/a~1b"), 1);
assertEquals(get(doc, "/c%d"), 2);
assertEquals(get(doc, "/e^f"), 3);
assertEquals(get(doc, "/g|h"), 4);
assertEquals(get(doc, "/i\\j"), 5);
assertEquals(get(doc, "/k\"l"), 6);
assertEquals(get(doc, "/ "), 7);
assertEquals(get(doc, "/m~0n"), 8);
assertEquals(set(doc, "/", 10), 10);
assertEquals(doc[""], 10);
assertEquals(set(doc, "/foo/0", 10), 10);
return assertEquals(doc.foo[0], 10);
},
name: "JSONPointer",
path: "glass.JSONPointer",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONPointer._decodeStep": "_decodeStep",
"glass.JSONPointer._getLastStep": "_getLastStep",
"glass.JSONPointer._getParent": "_getParent",
"glass.JSONPointer.toArray": "toArray",
"glass.JSONPointer.get": "get",
"glass.JSONPointer.set": "set",
"glass.assertEquals": "assertEquals"
},
uri: "global:/glass/JSONPointer"
}
},
"glass.Observable": {
source: "properties:
is: (type) -> @constructor.implements[type.path ? type] is true
watchers:
serializable: false
watch: (property, watcher) ->
if isFunction property
watcher = property
property = ''
id = getId watcher
@patch 'watchers', property, id, watcher
# returns a function which will remove the watch
=> @patch 'watchers', property, getId(watcher), undefined
patch: (change) ->
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
try
JSONMergePatch.apply this, change
catch e
console.log e
finally
@notify change
return
notify: (change) ->
if @watchers?
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
for property, watchers of @watchers
if property.length is 0 or change.hasOwnProperty property
changeArg = if property.length is 0 then change else change[property]
for id, watcher of watchers
watcher this, changeArg
return
toJSON: ->
values =
class: @constructor.path
# serialize statically defined properties
for name, property of @constructor.properties
value = @[name]
if property.serializable isnt false and not isFunction(value)
values[name] = value
# serialize custom properties if allowed by schema
if @constructor.additionalProperties isnt false
for own name, value of @ when not isPrivate name
values[name] = value
values
toString: -> @toJSON()
test:
toJSON: ->
# I need this test later
# on a class that actually has serializable properties
a = new Observable
a.x = 12
a.y = ->
a.z = true
assertEquals a, {class:'glass.Observable', x:12,z:true}
watchAll: ->
# we should actually be able to watch ourselves get added to watchers
# this is very meta.
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch watcher
# now make sure we were called with our own watcher
assert watchArgs[0] is a
assert watchArgs[1]?.watchers?[\"\"]?
# reset watchArgs, and watch something else
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assertEquals a.a, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {a:{b:3}}
# now unwatch
unwatch()
# make sure universal watcher is now empty
assertEquals a.watchers[\"\"], {}
# now reset and do a new event, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
watchProperty: ->
# watch a property
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch \"foo\", watcher
# now make sure we were not called
assert watchArgs.length is 0
# reset watchArgs, and watch something else
a.patch \"foo\", \"b\", 3
assertEquals a.foo, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {b:3}
# now reset and do a different property, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
# now unwatch
unwatch()
# make sure we no longer see foo
watchArgs.length = 0
a.patch \"foo\", \"b\", 4
assert watchArgs.length is 0
",
input: "runtime\\glass\\Observable.coffee",
content: {
properties: {
is: {
value: function(type) {
var _ref;
return this.constructor["implements"][(_ref = type.path) != null ? _ref: type] === true;
},
name: "is"
},
watchers: {
serializable: false,
name: "watchers",
writable: true
},
watch: {
value: function(property, watcher) {
var id, _this = this;
if (isFunction(property)) {
watcher = property;
property = '';
}
id = getId(watcher);
this.patch('watchers', property, id, watcher);
return function() {
return _this.patch('watchers', property, getId(watcher), void 0);
};
},
name: "watch"
},
patch: {
value: function(change) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
try {
JSONMergePatch.apply(this, change);
} catch(e) {
console.log(e);
} finally {
this.notify(change);
}
},
name: "patch"
},
notify: {
value: function(change) {
var changeArg, id, property, watcher, watchers, _ref;
if (this.watchers != null) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
_ref = this.watchers;
for (property in _ref) {
watchers = _ref[property];
if (property.length === 0 || change.hasOwnProperty(property)) {
changeArg = property.length === 0 ? change: change[property];
for (id in watchers) {
watcher = watchers[id];
watcher(this, changeArg);
}
}
}
}
},
name: "notify"
},
toJSON: {
value: function() {
var name, property, value, values, _ref;
values = {
"class": this.constructor.path
};
_ref = this.constructor.properties;
for (name in _ref) {
property = _ref[name];
value = this[name];
if (property.serializable !== false && !isFunction(value)) {
values[name] = value;
}
}
if (this.constructor.additionalProperties !== false) {
for (name in this) {
if (!__hasProp.call(this, name)) continue;
value = this[name];
if (!isPrivate(name)) {
values[name] = value;
}
}
}
return values;
},
name: "toJSON"
},
toString: {
value: function() {
return this.toJSON();
},
name: "toString"
}
},
test: {
toJSON: function() {
var a;
a = new Observable;
a.x = 12;
a.y = function() {};
a.z = true;
return assertEquals(a, {
"class": 'glass.Observable',
x: 12,
z: true
});
},
watchAll: function() {
var a, unwatch, watchArgs, watcher, _ref, _ref1;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch(watcher);
assert(watchArgs[0] === a);
assert(((_ref = watchArgs[1]) != null ? (_ref1 = _ref.watchers) != null ? _ref1[""] : void 0 : void 0) != null);
watchArgs.length = 0;
a.patch("a", "b", 3);
assertEquals(a.a, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
a: {
b: 3
}
});
unwatch();
assertEquals(a.watchers[""], {});
watchArgs.length = 0;
a.patch("a", "b", 3);
return assert(watchArgs.length === 0);
},
watchProperty: function() {
var a, unwatch, watchArgs, watcher;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch("foo", watcher);
assert(watchArgs.length === 0);
a.patch("foo", "b", 3);
assertEquals(a.foo, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
b: 3
});
watchArgs.length = 0;
a.patch("a", "b", 3);
assert(watchArgs.length === 0);
unwatch();
watchArgs.length = 0;
a.patch("foo", "b", 4);
return assert(watchArgs.length === 0);
}
},
name: "Observable",
path: "glass.Observable",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONMergePatch": "JSONMergePatch",
"glass.isFunction": "isFunction",
"glass.isPrivate": "isPrivate",
"glass.values": "values",
"glass.patch": "patch",
"glass.assert": "assert",
"glass.assertEquals": "assertEquals",
"glass.getId": "getId"
},
implements: {
"glass.Observable": true
},
uri: "global:/glass/Observable"
}
},
"glass.Component": {
source: "extends: 'Observable'
constructor: (properties) ->
@patch properties
# now site ourselves on our parent
if @parent
id = getId @
patch @parent, id, @
@
properties:
id:
description: 'string which uniquely identifies this component within its parent'
type: 'string'
parent:
description: 'the object that contains this component'
serializable: false
type: 'object'
disposed: false
dispose: -> @patch 'disposed', true
notify: (change) ->
Observable.prototype.notify.apply this, arguments
if change?.disposed
# dispose of any disposable children
for id, child of @ when child?.parent is @
child.dispose?()
# remove self from parent
if @id and @parent
patch @parent, @id, undefined
return
test:
lifecycle: ->
parent = new Component
assert not parent.id?
assert not parent.parent?
child = new Component parent:parent
# id should be automatically assigned
assert isString child.id
assert parent is child.parent
assert parent[child.id] is child
assert parent.hasOwnProperty child.id
parent.dispose()
assert child.disposed is true
assert not parent.hasOwnProperty child.id
nonEnumerability: ->
visibleKeys = (key for key of new Component)
assertEquals visibleKeys, []",
input: "runtime\\glass\\Component.coffee",
content: {
extends: ["glass.Observable"],
constructor: function(properties) {
var id;
this.patch(properties);
if (this.parent) {
id = getId(this);
patch(this.parent, id, this);
}
return this;
},
properties: {
id: {
description: "string which uniquely identifies this component within its parent",
type: "string",
name: "id",
writable: true
},
parent: {
description: "the object that contains this component",
serializable: false,
type: "object",
name: "parent",
writable: true
},
disposed: {
value: false,
name: "disposed",
writable: true
},
dispose: {
value: function() {
return this.patch('disposed', true);
},
name: "dispose"
},
notify: {
value: function(change) {
var child, id;
Observable.prototype.notify.apply(this, arguments);
if (change != null ? change.disposed: void 0) {
for (id in this) {
child = this[id];
if ((child != null ? child.parent: void 0) === this) {
if (typeof child.dispose === "function") {
child.dispose();
}
}
}
if (this.id && this.parent) {
patch(this.parent, this.id, void 0);
}
}
},
name: "notify"
}
},
test: {
lifecycle: function() {
var child, parent;
parent = new Component;
assert(!(parent.id != null));
assert(!(parent.parent != null));
child = new Component({
parent: parent
});
assert(isString(child.id));
assert(parent === child.parent);
assert(parent[child.id] === child);
assert(parent.hasOwnProperty(child.id));
parent.dispose();
assert(child.disposed === true);
return assert(!parent.hasOwnProperty(child.id));
},
nonEnumerability: function() {
var key, visibleKeys;
visibleKeys = (function() {
var _results;
_results = [];
for (key in new Component) {
_results.push(key);
}
return _results;
})();
return assertEquals(visibleKeys, []);
}
},
name: "Component",
path: "glass.Component",
namespace: "glass",
require: {
glass: "glass",
"glass.Observable": "Observable"
},
import: {
"glass.Observable": "Observable",
"glass.isString": "isString",
"glass.patch": "patch",
"glass.assert": "assert",
"glass.assertEquals": "assertEquals",
"glass.getId": "getId"
},
implements: {
"glass.Component": true,
"glass.Observable": true
},
uri: "global:/glass/Component"
}
},
"glass.Container": {
source: "extends: 'Observable'
properties:
watch: ->
unwatch: ->
",
input: "runtime\\glass\\Container.coffee",
content: {
extends: ["glass.Observable"],
properties: {
watch: {
value: function() {},
name: "watch"
},
unwatch: {
value: function() {},
name: "unwatch"
}
},
name: "Container",
path: "glass.Container",
namespace: "glass",
require: {
glass: "glass",
"glass.Observable": "Observable"
},
import: {},
implements: {
"glass.Container": true,
"glass.Observable": true
},
uri: "global:/glass/Container"
}
},
"glass.Expression._parser": {
source: "{
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e,array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++)
array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
}
start = expression
expression = conditional
conditional = e:or args:(\"?\" b:expression \":\" c:expression {return [b,c];})* {
while (args.length > 0) {
e = expr(\"?:\", [e].concat(args.pop()));
}
return e;
}
or = a:and b:((\"or\") and)* { return joinLeft(a,b); }
and = a:equality b:((\"and\") equality)* { return joinLeft(a,b); }
equality = a:rel b:((\"==\" / \"!=\") rel)* { return joinLeft(a,b); }
rel = a:sum b:((\"<=\" / \">=\" / \"<\" / \">\") sum)* { return joinLeft(a,b); }
sum = a:product b:((\"+\" / \"-\") product)* { return joinLeft(a,b); }
product = a:not b:((\"*\" / \"div\" / \"mod\") not)* { return joinLeft(a,b); }
not = ops:(s op:(\"!\" / \"~\" / \"+\" / \"-\") { return op; })* b:primary { return unaryRight(ops,b); }
primary = s a:(group / literal / path) s { return a; }
group = \"(\" a:expression \")\" { return a; }
literal = s a:(boolean / number / string / array / object) s { return a; }
boolean = a:(\"true\" / \"false\") { return a == \"true\"; }
number = a:([0-9]+ (\".\" [0-9]+)?) { return parseFloat(toString(a)); }
hex = [a-fA-F0-9]
// as per JSON http://www.json.org
string = a:( '\"' (
[\\u0000-\\u0021\\u0023-\\u005c\\u005e-\\uffff] // all unicode chars except \\ and \"
/ (\"\\\\\" (\"\\\"\" / \"\\\\\" / \"\\/\" / \"b\" / \"f\" / \"n\" / \"r\" / \"t\" / (\"u\" hex hex hex hex)))
)* '\"' )
{ return JSON.parse(toString(a)); }
array = \"[\" a:values \"]\" { return expr(\"array\", a); }
values = first:expression? args:(\",\" b:expression {return b;})* {
if (first != \"\") { args.unshift(first); } return args;
}
object = \"{\" a:keyvalues \"}\" { return expr(\"object\", a); }
keyvalue = s a:string s \":\" b:expression { return [a,b]; }
keyvalues = first:keyvalue? rest:(\",\" b:keyvalue {return b;})* {
if (first) { rest.unshift(first); } return rest;
}
ref = a:(\"//\" / \"/\" / \"$\" / \"**\" / \"*\" / \"..\" / \".\") b:slashProperty? {
e = expr(a); if (b) { b.args.unshift(e); e = b; } return e;
}
/ a:id { return expr(\"ref\", [a]); }
id = a:[a-z_]+ b:[a-z_0-9]* { return a.join('') + b.join(''); }
property = \"/\" a:slashProperty { return a; }
/ \"{\" a:expression \"}\" { return expr(\"{}\", [a]); } // locally scoped expression
/ \"[\" a:expression \"]\" { return expr(\"[]\", [a]); } // predicate
slashProperty = a:(id/number/string) { return expr(\"/\", [a]); }
/ a:(\"..\" / \"*\") { return expr(a, []); }
s \"space\" = [ ]* { return ''; }
path = a:root b:step* {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
}
root = a:implicitDotRoot b:dotStep? { return joinPath(a,b); }
/ explicitDotRoot
step = \".\" a:dotStep { return a; }
/ noDotStep
implicitDotRoot = \"/\" { return expr(\"root\"); }
/ \"@\" { return expr(\"this\"); }
/ \".\" a:\".\"+ { return expr(\"ancestor\", [a.length]); }
explicitDotRoot = a:id { return expr(\"ref\", [a]); }
/ \"*\" { return expr(\"values\", []); }
dotStep = a:(id / string / number) { return expr(\"get\", [a]); }
/ \"*\" { return expr(\"values\", []); }
noDotStep = \"{\" a:expression \"}\" { return expr(\"eval\", [a]); }
/ \"[\" a:expression \"]\" { return expr(\"pred\", [a]); }
/ \"(\" a:values \")\" { return expr(\"call\", [a]); }
",
input: "runtime\\glass\\Expression\\_parser.pegjs",
content: {
value: {
parse: function(input, startRule) {
var parseFunctions = {
"conditional": parse_conditional,
"or": parse_or,
"and": parse_and,
"equality": parse_equality,
"rel": parse_rel,
"sum": parse_sum,
"product": parse_product,
"not": parse_not,
"primary": parse_primary,
"group": parse_group,
"literal": parse_literal,
"boolean": parse_boolean,
"number": parse_number,
"hex": parse_hex,
"string": parse_string,
"array": parse_array,
"values": parse_values,
"object": parse_object,
"keyvalue": parse_keyvalue,
"keyvalues": parse_keyvalues,
"ref": parse_ref,
"id": parse_id,
"property": parse_property,
"slashProperty": parse_slashProperty,
"s": parse_s,
"path": parse_path,
"root": parse_root,
"step": parse_step,
"implicitDotRoot": parse_implicitDotRoot,
"explicitDotRoot": parse_explicitDotRoot,
"dotStep": parse_dotStep,
"noDotStep": parse_noDotStep
};
if (startRule !== undefined) {
if (parseFunctions[startRule] === undefined) {
throw new Error("Invalid rule name: " + quote(startRule) + ".");
}
} else {
startRule = "conditional";
}
var pos = 0;
var reportFailures = 0;
var rightmostFailuresPos = 0;
var rightmostFailuresExpected = [];
function padLeft(input, padding, length) {
var result = input;
var padLength = length - input.length;
for (var i = 0; i < padLength; i++) {
result = padding + result;
}
return result;
}
function escape(ch) {
var charCode = ch.charCodeAt(0);
var escapeChar;
var length;
if (charCode <= 0xFF) {
escapeChar = 'x';
length = 2;
} else {
escapeChar = 'u';
length = 4;
}
return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
}
function matchFailed(failure) {
if (pos < rightmostFailuresPos) {
return;
}
if (pos > rightmostFailuresPos) {
rightmostFailuresPos = pos;
rightmostFailuresExpected = [];
}
rightmostFailuresExpected.push(failure);
}
function parse_conditional() {
var result0, result1, result2, result3, result4, result5;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_or();
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, e, args) {
while (args.length > 0) {
e = expr("?:", [e].concat(args.pop()));
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_or() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_and();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_and() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_equality();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_equality() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_rel();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_rel() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_sum();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_sum() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_product();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_product() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_not();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_not() {
var result0, result1, result2;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = [];
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
while (result1 !== null) {
result0.push(result1);
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
}
if (result0 !== null) {
result1 = parse_primary();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, ops, b) {
return unaryRight(ops, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_primary() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_group();
if (result1 === null) {
result1 = parse_literal();
if (result1 === null) {
result1 = parse_path();
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_group() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_literal() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_boolean();
if (result1 === null) {
result1 = parse_number();
if (result1 === null) {
result1 = parse_string();
if (result1 === null) {
result1 = parse_array();
if (result1 === null) {
result1 = parse_object();
}
}
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_boolean() {
var result0;
var pos0;
pos0 = pos;
if (input.substr(pos, 4) === "true") {
result0 = "true";
pos += 4;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"true\"");
}
}
if (result0 === null) {
if (input.substr(pos, 5) === "false") {
result0 = "false";
pos += 5;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"false\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a == "true";
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_number() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
pos2 = pos;
if (input.charCodeAt(pos) === 46) {
result1 = ".";
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result1 !== null) {
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result3 !== null) {
result2 = [];
while (result3 !== null) {
result2.push(result3);
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result2 = null;
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos2;
}
} else {
result1 = null;
pos = pos2;
}
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return parseFloat(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_hex() {
var result0;
if (/^[a-fA-F0-9]/.test(input.charAt(pos))) {
result0 = input.charAt(pos);
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("[a-fA-F0-9]");
}
}
return result0;
}
function parse_string() {
var result0, result1, result2, result3, result4, result5, result6, result7;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 34) {
result0 = "\"";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result0 !== null) {
result1 = [];
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
}
if (result1 !== null) {
if (input.charCodeAt(pos) === 34) {
result2 = "\"";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return JSON.parse(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_array() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("array", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_values() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_conditional();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, args) {
if (first != "") {
args.unshift(first);
}
return args;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_object() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_keyvalues();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("object", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalue() {
var result0, result1, result2, result3, result4;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_string();
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
if (input.charCodeAt(pos) === 58) {
result3 = ":";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result3 !== null) {
result4 = parse_conditional();
if (result4 !== null) {
result0 = [result0, result1, result2, result3, result4];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return [a, b];
})(pos0, result0[1], result0[4]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalues() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_keyvalue();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, rest) {
if (first) {
rest.unshift(first);
}
return rest;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_ref() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.substr(pos, 2) === "//") {
result0 = "//";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"//\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 36) {
result0 = "$";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"$\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "**") {
result0 = "**";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"**\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
}
}
}
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
e = expr(a);
if (b) {
b.args.unshift(e);
e = b;
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_id() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
result1 = [];
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return a.join('') + b.join('');
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_property() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("{}", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("[]", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_slashProperty() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_number();
if (result0 === null) {
result0 = parse_string();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("/", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(a, []);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_s() {
var result0, result1;
var pos0;
reportFailures++;
pos0 = pos;
result0 = [];
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
while (result1 !== null) {
result0.push(result1);
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
}
if (result0 !== null) {
result0 = (function(offset) {
return '';
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
reportFailures--;
if (reportFailures === 0 && result0 === null) {
matchFailed("space");
}
return result0;
}
function parse_path() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_root();
if (result0 !== null) {
result1 = [];
result2 = parse_step();
while (result2 !== null) {
result1.push(result2);
result2 = parse_step();
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_root() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_implicitDotRoot();
if (result0 !== null) {
result1 = parse_dotStep();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinPath(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_explicitDotRoot();
}
return result0;
}
function parse_step() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
result1 = parse_dotStep();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_noDotStep();
}
return result0;
}
function parse_implicitDotRoot() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("root");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 64) {
result0 = "@";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"@\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("this");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result2 !== null) {
result1 = [];
while (result2 !== null) {
result1.push(result2);
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
} else {
result1 = null;
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ancestor", [a.length]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_explicitDotRoot() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_dotStep() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_string();
if (result0 === null) {
result0 = parse_number();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("get", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_noDotStep() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("eval", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("pred", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("call", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function cleanupExpected(expected) {
expected.sort();
var lastExpected = null;
var cleanExpected = [];
for (var i = 0; i < expected.length; i++) {
if (expected[i] !== lastExpected) {
cleanExpected.push(expected[i]);
lastExpected = expected[i];
}
}
return cleanExpected;
}
function computeErrorPosition() {
/*
* The first idea was to use |String.split| to break the input up to the
* error position along newlines and derive the line and column from
* there. However IE's |split| implementation is so broken that it was
* enough to prevent it.
*/
var line = 1;
var column = 1;
var seenCR = false;
for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
var ch = input.charAt(i);
if (ch === "
") {
if (!seenCR) {
line++;
}
column = 1;
seenCR = false;
} else if (ch === "
" || ch === "\u2028" || ch === "\u2029") {
line++;
column = 1;
seenCR = true;
} else {
column++;
seenCR = false;
}
}
return {
line: line,
column: column
};
}
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e, array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++) array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
var result = parseFunctions[startRule]();
/*
* The parser is now in one of the following three states:
*
* 1. The parser successfully parsed the whole input.
*
* - |result !== null|
* - |pos === input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 2. The parser successfully parsed only a part of the input.
*
* - |result !== null|
* - |pos < input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 3. The parser did not successfully parse any part of the input.
*
* - |result === null|
* - |pos === 0|
* - |rightmostFailuresExpected| contains at least one failure
*
* All code following this comment (including called functions) must
* handle these states.
*/
if (result === null || pos !== input.length) {
var offset = Math.max(pos, rightmostFailuresPos);
var found = offset < input.length ? input.charAt(offset) : null;
var errorPosition = computeErrorPosition();
throw new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column);
}
return result;
},
toSource: function() {
return this._source;
},
SyntaxError: function(expected, found, offset, line, column) {
function buildMessage(expected, found) {
var expectedHumanized, foundHumanized;
switch (expected.length) {
case 0:
expectedHumanized = "end of input";
break;
case 1:
expectedHumanized = expected[0];
break;
default:
expectedHumanized = expected.slice(0, expected.length - 1).join(", ") + " or " + expected[expected.length - 1];
}
foundHumanized = found ? quote(found) : "end of input";
return "Expected " + expectedHumanized + " but " + foundHumanized + " found.";
}
this.name = "SyntaxError";
this.expected = expected;
this.found = found;
this.message = buildMessage(expected, found);
this.offset = offset;
this.line = line;
this.column = column;
}
},
name: "_parser",
path: "glass.Expression._parser",
namespace: "glass.Expression",
require: {
"glass.Expression": "Expression"
},
import: {
"glass.values": "values"
},
uri: "global:/glass/Expression/_parser"
}
},
"glass.allTests": {
content: {
path: "glass.allTests",
name: "allTests",
namespace: "glass",
import: {
glass: "glass",
"glass.Expression": "glass_Expression",
"glass.JSONMergePatch": "glass_JSONMergePatch",
"glass.JSONPointer": "glass_JSONPointer",
"glass.Observable": "glass_Observable",
"glass.Component": "glass_Component"
},
value: function anonymous(callback) {
if (callback == null) {
callback = function(path, result) {
if (result == null) {
console.log("\033[92mPass\033[0m: " + path + "");
} else {
console.log("\033[91mFail\033[0m: " + path + "");
console.log(result.stack || result);
}
}
}
function singleTest(path, test) {
if (test == null) {
callback(path, "test not found");
return;
} else if (typeof test == 'object') {
for (var key in test) singleTest(path + '.' + key, test[key]);
return;
}
try {
callback(path, test());
} catch(e) {
callback(path, e);
}
}
singleTest("glass", glass.test);
singleTest("glass.Expression", glass_Expression.test);
singleTest("glass.JSONMergePatch", glass_JSONMergePatch.test);
singleTest("glass.JSONPointer", glass_JSONPointer.test);
singleTest("glass.Observable", glass_Observable.test);
singleTest("glass.Component", glass_Component.test);
}
}
}
}
} | {
options: {
input: {
dir: "runtime",
match: /\.(coffee|pegjs)$/
},
output: {
dir: "www/js"
},
script: {
includes: "www/includes.html",
prefix: "/js/"
},
module: {
main: "glass.js",
prefix: "./www/js/"
},
debug: "buildlog.html",
test: "glass.allTests",
addon: {
pregenerate: {
addUri: function(schema) {
var content, type, typeName, _ref2, _ref3;
_ref2 = schema.types;
for (typeName in _ref2) {
type = _ref2[typeName];
content = type.content;
if (content.extension) {
continue;
}
if ((_ref3 = content.uri) == null) {
content.uri = "global:/" + (content.path.replace(/\./g, '/'));
}
}
return schema;
}
}
},
namespace: ""
},
types: {
String: {
source: "extension: true
properties:
\tstartsWith: (s) -> @slice(0,s.length) is s
\tendsWith: (s) -> @slice(-s.length) is s
\tcontains: (s) -> @indexOf(s) >= 0
\ttoArray: () -> @split ''",
input: "runtime\\String.coffee",
content: {
extension: true,
properties: {
startsWith: {
value: function(s) {
return this.slice(0, s.length) === s;
},
name: "startsWith"
},
endsWith: {
value: function(s) {
return this.slice( - s.length) === s;
},
name: "endsWith"
},
contains: {
value: function(s) {
return this.indexOf(s) >= 0;
},
name: "contains"
},
toArray: {
value: function() {
return this.split('');
},
name: "toArray"
}
},
name: "String",
path: "String",
namespace: "",
require: {},
import: {},
implements: {
String: true
}
},
isFirst: true,
output: "www\\js\\String.js"
},
glass: {
source: "require:
\tString: true
# runtime type tests
isFunction: (object) -> object? and typeof object is 'function'
isString: (object) -> object?.constructor is String
isArray: (object) -> Array.isArray object
isBoolean: (object) -> object? and typeof object is 'boolean'
isNumber: (object) -> object? and typeof object is 'number'
isObject: (object) -> typeof object is 'object'
isPlainObject: (object) -> object?.constructor is Object
isPrototype: (object) -> object? and object is object.constructor.prototype
isDate: (object) -> object?.constructor is Date
isPrimitive: (object) -> isString(object) or isBoolean(object) or isNumber(object) or isDate(object)
isPrivate: (property) -> property?[0] is '_'
# generic utility functions
values: (object) -> (value for key, value of object)
# generic patch method, uses patch method built into object if present
patch: (target, pathAndPatch...) ->
patch = JSONMergePatch.create.apply null, pathAndPatch
if isFunction target?.patch
target.patch patch
else
glass.JSONMergePatch.apply target, patch
# testing assertions
_getStackLocationInfo: (e, depth) ->
line = e.stack?.split('
')[depth]
return null unless line?
match = /\\(([\\w\\W]*?):(\\d+):(\\d+)\\)/.exec line
return {
file: match[1]
line: parseInt match[2]
column: parseInt match[3]
}
_throwAssertionFailure: (message) ->
try
throw new Error \"Assertion failed: \" + message
catch e
info = _getStackLocationInfo e, 3
if info?
_dumpFile info.file, info.line - 2, info.line + 2, info.line
throw e
_dumpFile: (file, from=1, to, highlight) ->
fs = require 'fs'
return unless fs?
try
content = fs.readFileSync(file).toString()
catch e
content = \"Source not found: #{e}\"
console.log '------------------------------------------------'
console.log file
console.log '------------------------------------------------'
number = 1
if content?
lines = content.split /
|
/
to ?= lines.length
for line in lines
lineNumber = number++
if lineNumber >= from and lineNumber <= to
num = String lineNumber
while num.length < 3
num += ' '
if lineNumber is highlight
`console.log(\"\\033[91m\" + num + \": \" + line + \"\\033[0m\");`
else
`console.log(num + \": \" + line);`
console.log '------------------------------------------------'
assert: (a) ->
_throwAssertionFailure JSON.stringify(a) unless a
assertTrue: (a) ->
_throwAssertionFailure JSON.stringify(a) + \" != true\" unless a is true
assertEquals: (a, b) ->
if JSON.stringify(a) isnt JSON.stringify(b)
_throwAssertionFailure JSON.stringify(a) + ' != ' + JSON.stringify(b)
# gets a unique string identifier for any object
getId:
do: ->
counter = 0
(a) ->
if a is null
return '__null__'
if a is undefined
return '__undefined__'
if typeof a is 'object' or typeof a is 'function'
return a.id ?= '__' + (counter++) + '__'
# 12 == \"12\" under this technique
return a.toString()
getType: (path) ->
array = if isArray path then path else path.split '.'
value = global
for step in path when value?
value = value[step]
throw new Error \"Type not found: #{path}\" unless isFunction value
value
test:
values: ->
assertEquals values({a:1,b:3,c:2}), [1,3,2]
patch: ->
x = {a:{foo:1,bar:3},b:2}
patch x, 'a', 'foo', 5
assertEquals x.a.foo, 5
",
input: "runtime\\glass.coffee",
content: {
require: {
String: "String"
},
isFunction: function(object) {
return (object != null) && typeof object === 'function';
},
isString: function(object) {
return (object != null ? object.constructor: void 0) === String;
},
isArray: function(object) {
return Array.isArray(object);
},
isBoolean: function(object) {
return (object != null) && typeof object === 'boolean';
},
isNumber: function(object) {
return (object != null) && typeof object === 'number';
},
isObject: function(object) {
return typeof object === 'object';
},
isPlainObject: function(object) {
return (object != null ? object.constructor: void 0) === Object;
},
isPrototype: function(object) {
return (object != null) && object === object.constructor.prototype;
},
isDate: function(object) {
return (object != null ? object.constructor: void 0) === Date;
},
isPrimitive: function(object) {
return isString(object) || isBoolean(object) || isNumber(object) || isDate(object);
},
isPrivate: function(property) {
return (property != null ? property[0] : void 0) === '_';
},
values: function(object) {
var key, value, _results;
_results = [];
for (key in object) {
value = object[key];
_results.push(value);
}
return _results;
},
patch: function() {
var patch, pathAndPatch, target;
target = arguments[0],
pathAndPatch = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
patch = JSONMergePatch.create.apply(null, pathAndPatch);
if (isFunction(target != null ? target.patch: void 0)) {
return target.patch(patch);
} else {
return glass.JSONMergePatch.apply(target, patch);
}
},
assert: function(a) {
if (!a) {
return _throwAssertionFailure(JSON.stringify(a));
}
},
assertTrue: function(a) {
if (a !== true) {
return _throwAssertionFailure(JSON.stringify(a) + " != true");
}
},
assertEquals: function(a, b) {
if (JSON.stringify(a) !== JSON.stringify(b)) {
return _throwAssertionFailure(JSON.stringify(a) + ' != ' + JSON.stringify(b));
}
},
getId: {
do: function() {
var counter;
counter = 0;
return function(a) {
var _ref;
if (a === null) {
return '__null__';
}
if (a === void 0) {
return '__undefined__';
}
if (typeof a === 'object' || typeof a === 'function') {
return (_ref = a.id) != null ? _ref: a.id = '__' + (counter++) + '__';
}
return a.toString();
};
}
},
getType: function(path) {
var array, step, value, _i, _len;
array = isArray(path) ? path: path.split('.');
value = global;
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
if (!isFunction(value)) {
throw new Error("Type not found: " + path);
}
return value;
},
test: {
values: function() {
return assertEquals(values({
a: 1,
b: 3,
c: 2
}), [1, 3, 2]);
},
patch: function() {
var x;
x = {
a: {
foo: 1,
bar: 3
},
b: 2
};
patch(x, 'a', 'foo', 5);
return assertEquals(x.a.foo, 5);
}
},
name: "glass",
path: "glass",
namespace: "",
import: {
"glass.JSONMergePatch": "JSONMergePatch",
"glass.isFunction": "isFunction",
"glass.isString": "isString",
"glass.isArray": "isArray",
"glass.isBoolean": "isBoolean",
"glass.isNumber": "isNumber",
"glass.isDate": "isDate",
"glass.values": "values",
"glass.patch": "patch",
"glass._getStackLocationInfo": "_getStackLocationInfo",
"glass._throwAssertionFailure": "_throwAssertionFailure",
"glass._dumpFile": "_dumpFile",
"glass.assertEquals": "assertEquals"
},
uri: "global:/glass"
},
output: "www\\js\\glass.js"
},
"glass.Expression": {
source: "constructor: (op, args) ->
@op = op
@args = args if args?
@
properties:
op:
type: 'string'
args:
type: 'array'
test: ->
return
peg = require 'pegjs'
fs = require 'fs'
parserSource = fs.readFileSync 'runtime/glass/Expression/_parser.pegjs', 'utf8'
parser = peg.buildParser parserSource
tests =
\"a.b.c\": {op:\"get\",args:[{op:\"get\",args:[{op:\"ref\",args:[\"a\"]},\"b\"]},\"c\"]}
\"a.1\": {op:\"get\",args:[{op:\"ref\",args:[\"a\"]},1]}
\"true\": true
\"false\": false
\"45.8\": 45.8
\"(45.8)\": 45.8
\"((45.8))\": 45.8
\"alpha\": {op:\"ref\",args:[\"alpha\"]}
\"35 + true * 2\": {op:\"+\", args:[35, {op:\"*\", args:[true,2]}]}
\" 5 * ( 2 + 2 ) \": {op:\"*\", args:[5, {op:\"+\", args:[2,2]}]}
\" ! ! true\": {op:\"!\",args:[{op:\"!\",args:[true]}]}
\"5 + -x\": {op:\"+\",args:[5,{op:\"-\",args:[{op:\"ref\",args:[\"x\"]}]}]}
\"true == 5 >= 2\": {op:\"==\",args:[true,{op:\">=\",args:[5,2]}]}
\"1 or 2 and 3\": {op:\"or\",args:[1,{op:\"and\",args:[2,3]}]}
\"1 ? 2 : 3\": {op:\"?:\",args:[1,2,3]}
\"1 ? 2 : 3 ? 4 : 5\" : {op:\"?:\",args:[1,2,{op:\"?:\",args:[3,4,5]}]}
\"a()(1,2)\" : {op:\"call\",args:[{op:\"call\",args:[{op:\"ref\",args:[\"a\"]},[]]},[1,2]]}
\"@\" : {op:\"this\"}
\"@foo\" : {op:\"get\",args:[{op:\"this\"},\"foo\"]}
'\"hello\"': \"hello\"
'\"\\\\t\\
\\
\\\\b\\\\\\\\foo\\\\\\/\"' : \"\\t
\\b\\\\foo\\/\"
\"[]\": {op:\"array\",args:[]}
\"[1,2]\": {op:\"array\",args:[1,2]}
\"[1+2]\": {op:\"array\",args:[{op:\"+\",args:[1,2]}]}
\"{}\": {op:\"object\",args:[]}
'{\"a\":2}': {op:\"object\",args:[[\"a\",2]]}
'{\"a\":2,\"b\":1+2}': {op:\"object\",args:[[\"a\",2],[\"b\",{op:\"+\",args:[1,2]}]]}
'@\"alpha\"': {op:\"get\",args:[{op:\"this\"},\"alpha\"]}
'*': {op:\"values\",args:[]}
'*.*': {op:\"values\",args:[{op:\"values\",args:[]}]}
\"foo.*\": {op:\"values\",args:[{op:\"ref\",args:[\"foo\"]}]}
\"..\": {op:\"ancestor\",args:[1]}
\"...\": {op:\"ancestor\",args:[2]}
\"@*{1+2}\": {op:\"eval\",args:[{op:\"values\",args:[{op:\"this\"}]},{op:\"+\",args:[1,2]}]}
\"/\": {op:\"root\"}
\"/foo\": {op:\"get\",args:[{op:\"root\"},\"foo\"]}
\"/*\": {op:\"values\",args:[{op:\"root\"}]}
for text, expected of tests
result = parser.parse text
if JSON.stringify(result) is JSON.stringify(expected)
console.log 'Pass: ' + text
else
console.log text, JSON.stringify result
return
",
input: "runtime\\glass\\Expression.coffee",
content: {
constructor: function(op, args) {
this.op = op;
if (args != null) {
this.args = args;
}
return this;
},
properties: {
op: {
type: "string",
name: "op",
writable: true
},
args: {
type: "array",
name: "args",
writable: true
}
},
test: function() {
var expected, fs, parser, parserSource, peg, result, tests, text;
return;
peg = require('pegjs');
fs = require('fs');
parserSource = fs.readFileSync('runtime/glass/Expression/_parser.pegjs', 'utf8');
parser = peg.buildParser(parserSource);
tests = {
"a.b.c": {
op: "get",
args: [{
op: "get",
args: [{
op: "ref",
args: ["a"]
},
"b"]
},
"c"]
},
"a.1": {
op: "get",
args: [{
op: "ref",
args: ["a"]
},
1]
},
"true": true,
"false": false,
"45.8": 45.8,
"(45.8)": 45.8,
"((45.8))": 45.8,
"alpha": {
op: "ref",
args: ["alpha"]
},
"35 + true * 2": {
op: "+",
args: [35, {
op: "*",
args: [true, 2]
}]
},
" 5 * ( 2 + 2 ) ": {
op: "*",
args: [5, {
op: "+",
args: [2, 2]
}]
},
" ! ! true": {
op: "!",
args: [{
op: "!",
args: [true]
}]
},
"5 + -x": {
op: "+",
args: [5, {
op: "-",
args: [{
op: "ref",
args: ["x"]
}]
}]
},
"true == 5 >= 2": {
op: "==",
args: [true, {
op: ">=",
args: [5, 2]
}]
},
"1 or 2 and 3": {
op: "or",
args: [1, {
op: "and",
args: [2, 3]
}]
},
"1 ? 2 : 3": {
op: "?:",
args: [1, 2, 3]
},
"1 ? 2 : 3 ? 4 : 5": {
op: "?:",
args: [1, 2, {
op: "?:",
args: [3, 4, 5]
}]
},
"a()(1,2)": {
op: "call",
args: [{
op: "call",
args: [{
op: "ref",
args: ["a"]
},
[]]
},
[1, 2]]
},
"@": {
op: "this"
},
"@foo": {
op: "get",
args: [{
op: "this"
},
"foo"]
},
'"hello"': "hello",
'"\\t
\\b\\\\foo\\\/"': "\t
\b\\foo\/",
"[]": {
op: "array",
args: []
},
"[1,2]": {
op: "array",
args: [1, 2]
},
"[1+2]": {
op: "array",
args: [{
op: "+",
args: [1, 2]
}]
},
"{}": {
op: "object",
args: []
},
'{"a":2}': {
op: "object",
args: [["a", 2]]
},
'{"a":2,"b":1+2}': {
op: "object",
args: [["a", 2], ["b", {
op: "+",
args: [1, 2]
}]]
},
'@"alpha"': {
op: "get",
args: [{
op: "this"
},
"alpha"]
},
'*': {
op: "values",
args: []
},
'*.*': {
op: "values",
args: [{
op: "values",
args: []
}]
},
"foo.*": {
op: "values",
args: [{
op: "ref",
args: ["foo"]
}]
},
"..": {
op: "ancestor",
args: [1]
},
"...": {
op: "ancestor",
args: [2]
},
"@*{1+2}": {
op: "eval",
args: [{
op: "values",
args: [{
op: "this"
}]
},
{
op: "+",
args: [1, 2]
}]
},
"/": {
op: "root"
},
"/foo": {
op: "get",
args: [{
op: "root"
},
"foo"]
},
"/*": {
op: "values",
args: [{
op: "root"
}]
}
};
for (text in tests) {
expected = tests[text];
result = parser.parse(text);
if (JSON.stringify(result) === JSON.stringify(expected)) {
console.log('Pass: ' + text);
} else {
console.log(text, JSON.stringify(result));
}
}
},
name: "Expression",
path: "glass.Expression",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.Expression._parser": "_parser",
"glass.values": "values"
},
implements: {
"glass.Expression": true
},
uri: "global:/glass/Expression"
},
output: "www\\js\\glass\\Expression.js"
},
"glass.JSONMergePatch": {
source: "
# applies a patch to the target object and returns the resulting target
apply: (target, patch) ->
if target? and target isnt patch and isPlainObject(patch) and not isPrimitive(target)
for key, value of patch
if value is undefined
delete target[key]
else
target[key] = apply target[key], patch[key]
return target
else
return patch
# (path1, path2, path3.., patch) ->
create: ->
if arguments.length is 1
return arguments[0]
result = {}
current = result
for arg, i in arguments when i + 1 < arguments.length
last = i + 2 is arguments.length
current = current[arg] = if last then arguments[arguments.length-1] else {}
result
test: ->
assertEquals {a:{b:12}}, create 'a', 'b', 12
assertEquals {a:3}, apply({a:1,b:2}, {a:3,b:undefined})
",
input: "runtime\\glass\\JSONMergePatch.coffee",
content: {
apply: function(target, patch) {
var key, value;
if ((target != null) && target !== patch && isPlainObject(patch) && !isPrimitive(target)) {
for (key in patch) {
value = patch[key];
if (value === void 0) {
delete target[key];
} else {
target[key] = apply(target[key], patch[key]);
}
}
return target;
} else {
return patch;
}
},
create: function() {
var arg, current, i, last, result, _i, _len;
if (arguments.length === 1) {
return arguments[0];
}
result = {};
current = result;
for (i = _i = 0, _len = arguments.length; _i < _len; i = ++_i) {
arg = arguments[i];
if (! (i + 1 < arguments.length)) {
continue;
}
last = i + 2 === arguments.length;
current = current[arg] = last ? arguments[arguments.length - 1] : {};
}
return result;
},
test: function() {
assertEquals({
a: {
b: 12
}
},
create('a', 'b', 12));
return assertEquals({
a: 3
},
apply({
a: 1,
b: 2
},
{
a: 3,
b: void 0
}));
},
name: "JSONMergePatch",
path: "glass.JSONMergePatch",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONMergePatch.apply": "apply",
"glass.JSONMergePatch.create": "create",
"glass.isPlainObject": "isPlainObject",
"glass.isPrimitive": "isPrimitive",
"glass.patch": "patch",
"glass.assertEquals": "assertEquals"
},
uri: "global:/glass/JSONMergePatch"
},
output: "www\\js\\glass\\JSONMergePatch.js"
},
"glass.JSONPointer": {
source: "# json pointer implementation as per
# http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-05
_decodeStep: (step) -> step.replace(/~1/g, '/').replace(/~0/g, '~')
_getLastStep: (pointer) ->
_decodeStep pointer.substring(pointer.lastIndexOf('/') + 1)
_getParent: (pointer) ->
if not pointer?.length
null
else
pointer.substring(0, pointer.lastIndexOf('/'))
toArray: (pointer) ->
for step in pointer.substring(1).split('/')
_decodeStep step
get: (doc, pointer) ->
value = doc
if pointer.length
path = toArray pointer
for step in path when value?
value = value[step]
value
set: (doc, pointer, value) ->
parentPointer = _getParent pointer
if parentPointer?
parent = get doc, parentPointer
lastStep = _getLastStep pointer
parent[lastStep] = value
value
test: ->
assertEquals _getParent(\"/a/b/c\"), \"/a/b\"
assertEquals _getParent(\"/a\"), \"\"
assertEquals _getParent(\"\"), null
assertEquals _getLastStep(\"/a/b/c\"), \"c\"
assertEquals _getLastStep(\"/a~0~1\"), \"a~/\"
assertEquals _getLastStep(\"\"), \"\"
# tests as per spec
doc = {
\"foo\": [\"bar\", \"baz\"],
\"\": 0,
\"a/b\": 1,
\"c%d\": 2,
\"e^f\": 3,
\"g|h\": 4,
\"i\\\\j\": 5,
\"k\\\"l\": 6,
\" \": 7,
\"m~n\": 8
}
assertEquals get(doc, \"\"), doc
assertEquals get(doc, \"/foo\"), [\"bar\", \"baz\"]
assertEquals get(doc, \"/foo/0\"), \"bar\"
assertEquals get(doc, \"/\"), 0
assertEquals get(doc, \"/a~1b\"), 1
assertEquals get(doc, \"/c%d\"), 2
assertEquals get(doc, \"/e^f\"), 3
assertEquals get(doc, \"/g|h\"), 4
assertEquals get(doc, \"/i\\\\j\"), 5
assertEquals get(doc, \"/k\\\"l\"), 6
assertEquals get(doc, \"/ \"), 7
assertEquals get(doc, \"/m~0n\"), 8
# now test set
assertEquals set(doc, \"/\", 10), 10
assertEquals doc[\"\"], 10
assertEquals set(doc, \"/foo/0\", 10), 10
assertEquals doc.foo[0], 10",
input: "runtime\\glass\\JSONPointer.coffee",
content: {
toArray: function(pointer) {
var step, _i, _len, _ref, _results;
_ref = pointer.substring(1).split('/');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
step = _ref[_i];
_results.push(_decodeStep(step));
}
return _results;
},
get: function(doc, pointer) {
var path, step, value, _i, _len;
value = doc;
if (pointer.length) {
path = toArray(pointer);
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
}
return value;
},
set: function(doc, pointer, value) {
var lastStep, parent, parentPointer;
parentPointer = _getParent(pointer);
if (parentPointer != null) {
parent = get(doc, parentPointer);
lastStep = _getLastStep(pointer);
parent[lastStep] = value;
}
return value;
},
test: function() {
var doc;
assertEquals(_getParent("/a/b/c"), "/a/b");
assertEquals(_getParent("/a"), "");
assertEquals(_getParent(""), null);
assertEquals(_getLastStep("/a/b/c"), "c");
assertEquals(_getLastStep("/a~0~1"), "a~/");
assertEquals(_getLastStep(""), "");
doc = {
"foo": ["bar", "baz"],
"": 0,
"a/b": 1,
"c%d": 2,
"e^f": 3,
"g|h": 4,
"i\\j": 5,
"k\"l": 6,
" ": 7,
"m~n": 8
};
assertEquals(get(doc, ""), doc);
assertEquals(get(doc, "/foo"), ["bar", "baz"]);
assertEquals(get(doc, "/foo/0"), "bar");
assertEquals(get(doc, "/"), 0);
assertEquals(get(doc, "/a~1b"), 1);
assertEquals(get(doc, "/c%d"), 2);
assertEquals(get(doc, "/e^f"), 3);
assertEquals(get(doc, "/g|h"), 4);
assertEquals(get(doc, "/i\\j"), 5);
assertEquals(get(doc, "/k\"l"), 6);
assertEquals(get(doc, "/ "), 7);
assertEquals(get(doc, "/m~0n"), 8);
assertEquals(set(doc, "/", 10), 10);
assertEquals(doc[""], 10);
assertEquals(set(doc, "/foo/0", 10), 10);
return assertEquals(doc.foo[0], 10);
},
name: "JSONPointer",
path: "glass.JSONPointer",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONPointer._decodeStep": "_decodeStep",
"glass.JSONPointer._getLastStep": "_getLastStep",
"glass.JSONPointer._getParent": "_getParent",
"glass.JSONPointer.toArray": "toArray",
"glass.JSONPointer.get": "get",
"glass.JSONPointer.set": "set",
"glass.assertEquals": "assertEquals"
},
uri: "global:/glass/JSONPointer"
},
output: "www\\js\\glass\\JSONPointer.js"
},
"glass.Observable": {
source: "properties:
is: (type) -> @constructor.implements[type.path ? type] is true
watchers:
serializable: false
watch: (property, watcher) ->
if isFunction property
watcher = property
property = ''
id = getId watcher
@patch 'watchers', property, id, watcher
# returns a function which will remove the watch
=> @patch 'watchers', property, getId(watcher), undefined
patch: (change) ->
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
try
JSONMergePatch.apply this, change
catch e
console.log e
finally
@notify change
return
notify: (change) ->
if @watchers?
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
for property, watchers of @watchers
if property.length is 0 or change.hasOwnProperty property
changeArg = if property.length is 0 then change else change[property]
for id, watcher of watchers
watcher this, changeArg
return
toJSON: ->
values =
class: @constructor.path
# serialize statically defined properties
for name, property of @constructor.properties
value = @[name]
if property.serializable isnt false and not isFunction(value)
values[name] = value
# serialize custom properties if allowed by schema
if @constructor.additionalProperties isnt false
for own name, value of @ when not isPrivate name
values[name] = value
values
toString: -> @toJSON()
test:
toJSON: ->
# I need this test later
# on a class that actually has serializable properties
a = new Observable
a.x = 12
a.y = ->
a.z = true
assertEquals a, {class:'glass.Observable', x:12,z:true}
watchAll: ->
# we should actually be able to watch ourselves get added to watchers
# this is very meta.
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch watcher
# now make sure we were called with our own watcher
assert watchArgs[0] is a
assert watchArgs[1]?.watchers?[\"\"]?
# reset watchArgs, and watch something else
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assertEquals a.a, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {a:{b:3}}
# now unwatch
unwatch()
# make sure universal watcher is now empty
assertEquals a.watchers[\"\"], {}
# now reset and do a new event, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
watchProperty: ->
# watch a property
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch \"foo\", watcher
# now make sure we were not called
assert watchArgs.length is 0
# reset watchArgs, and watch something else
a.patch \"foo\", \"b\", 3
assertEquals a.foo, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {b:3}
# now reset and do a different property, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
# now unwatch
unwatch()
# make sure we no longer see foo
watchArgs.length = 0
a.patch \"foo\", \"b\", 4
assert watchArgs.length is 0
",
input: "runtime\\glass\\Observable.coffee",
content: {
properties: {
is: {
value: function(type) {
var _ref;
return this.constructor["implements"][(_ref = type.path) != null ? _ref: type] === true;
},
name: "is"
},
watchers: {
serializable: false,
name: "watchers",
writable: true
},
watch: {
value: function(property, watcher) {
var id, _this = this;
if (isFunction(property)) {
watcher = property;
property = '';
}
id = getId(watcher);
this.patch('watchers', property, id, watcher);
return function() {
return _this.patch('watchers', property, getId(watcher), void 0);
};
},
name: "watch"
},
patch: {
value: function(change) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
try {
JSONMergePatch.apply(this, change);
} catch(e) {
console.log(e);
} finally {
this.notify(change);
}
},
name: "patch"
},
notify: {
value: function(change) {
var changeArg, id, property, watcher, watchers, _ref;
if (this.watchers != null) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
_ref = this.watchers;
for (property in _ref) {
watchers = _ref[property];
if (property.length === 0 || change.hasOwnProperty(property)) {
changeArg = property.length === 0 ? change: change[property];
for (id in watchers) {
watcher = watchers[id];
watcher(this, changeArg);
}
}
}
}
},
name: "notify"
},
toJSON: {
value: function() {
var name, property, value, values, _ref;
values = {
"class": this.constructor.path
};
_ref = this.constructor.properties;
for (name in _ref) {
property = _ref[name];
value = this[name];
if (property.serializable !== false && !isFunction(value)) {
values[name] = value;
}
}
if (this.constructor.additionalProperties !== false) {
for (name in this) {
if (!__hasProp.call(this, name)) continue;
value = this[name];
if (!isPrivate(name)) {
values[name] = value;
}
}
}
return values;
},
name: "toJSON"
},
toString: {
value: function() {
return this.toJSON();
},
name: "toString"
}
},
test: {
toJSON: function() {
var a;
a = new Observable;
a.x = 12;
a.y = function() {};
a.z = true;
return assertEquals(a, {
"class": 'glass.Observable',
x: 12,
z: true
});
},
watchAll: function() {
var a, unwatch, watchArgs, watcher, _ref, _ref1;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch(watcher);
assert(watchArgs[0] === a);
assert(((_ref = watchArgs[1]) != null ? (_ref1 = _ref.watchers) != null ? _ref1[""] : void 0 : void 0) != null);
watchArgs.length = 0;
a.patch("a", "b", 3);
assertEquals(a.a, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
a: {
b: 3
}
});
unwatch();
assertEquals(a.watchers[""], {});
watchArgs.length = 0;
a.patch("a", "b", 3);
return assert(watchArgs.length === 0);
},
watchProperty: function() {
var a, unwatch, watchArgs, watcher;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch("foo", watcher);
assert(watchArgs.length === 0);
a.patch("foo", "b", 3);
assertEquals(a.foo, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
b: 3
});
watchArgs.length = 0;
a.patch("a", "b", 3);
assert(watchArgs.length === 0);
unwatch();
watchArgs.length = 0;
a.patch("foo", "b", 4);
return assert(watchArgs.length === 0);
}
},
name: "Observable",
path: "glass.Observable",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONMergePatch": "JSONMergePatch",
"glass.isFunction": "isFunction",
"glass.isPrivate": "isPrivate",
"glass.values": "values",
"glass.patch": "patch",
"glass.assert": "assert",
"glass.assertEquals": "assertEquals",
"glass.getId": "getId"
},
implements: {
"glass.Observable": true
},
uri: "global:/glass/Observable"
},
output: "www\\js\\glass\\Observable.js"
},
"glass.Component": {
source: "extends: 'Observable'
constructor: (properties) ->
@patch properties
# now site ourselves on our parent
if @parent
id = getId @
patch @parent, id, @
@
properties:
id:
description: 'string which uniquely identifies this component within its parent'
type: 'string'
parent:
description: 'the object that contains this component'
serializable: false
type: 'object'
disposed: false
dispose: -> @patch 'disposed', true
notify: (change) ->
Observable.prototype.notify.apply this, arguments
if change?.disposed
# dispose of any disposable children
for id, child of @ when child?.parent is @
child.dispose?()
# remove self from parent
if @id and @parent
patch @parent, @id, undefined
return
test:
lifecycle: ->
parent = new Component
assert not parent.id?
assert not parent.parent?
child = new Component parent:parent
# id should be automatically assigned
assert isString child.id
assert parent is child.parent
assert parent[child.id] is child
assert parent.hasOwnProperty child.id
parent.dispose()
assert child.disposed is true
assert not parent.hasOwnProperty child.id
nonEnumerability: ->
visibleKeys = (key for key of new Component)
assertEquals visibleKeys, []",
input: "runtime\\glass\\Component.coffee",
content: {
extends: ["glass.Observable"],
constructor: function(properties) {
var id;
this.patch(properties);
if (this.parent) {
id = getId(this);
patch(this.parent, id, this);
}
return this;
},
properties: {
id: {
description: "string which uniquely identifies this component within its parent",
type: "string",
name: "id",
writable: true
},
parent: {
description: "the object that contains this component",
serializable: false,
type: "object",
name: "parent",
writable: true
},
disposed: {
value: false,
name: "disposed",
writable: true
},
dispose: {
value: function() {
return this.patch('disposed', true);
},
name: "dispose"
},
notify: {
value: function(change) {
var child, id;
Observable.prototype.notify.apply(this, arguments);
if (change != null ? change.disposed: void 0) {
for (id in this) {
child = this[id];
if ((child != null ? child.parent: void 0) === this) {
if (typeof child.dispose === "function") {
child.dispose();
}
}
}
if (this.id && this.parent) {
patch(this.parent, this.id, void 0);
}
}
},
name: "notify"
}
},
test: {
lifecycle: function() {
var child, parent;
parent = new Component;
assert(!(parent.id != null));
assert(!(parent.parent != null));
child = new Component({
parent: parent
});
assert(isString(child.id));
assert(parent === child.parent);
assert(parent[child.id] === child);
assert(parent.hasOwnProperty(child.id));
parent.dispose();
assert(child.disposed === true);
return assert(!parent.hasOwnProperty(child.id));
},
nonEnumerability: function() {
var key, visibleKeys;
visibleKeys = (function() {
var _results;
_results = [];
for (key in new Component) {
_results.push(key);
}
return _results;
})();
return assertEquals(visibleKeys, []);
}
},
name: "Component",
path: "glass.Component",
namespace: "glass",
require: {
glass: "glass",
"glass.Observable": "Observable"
},
import: {
"glass.Observable": "Observable",
"glass.isString": "isString",
"glass.patch": "patch",
"glass.assert": "assert",
"glass.assertEquals": "assertEquals",
"glass.getId": "getId"
},
implements: {
"glass.Component": true,
"glass.Observable": true
},
uri: "global:/glass/Component"
},
output: "www\\js\\glass\\Component.js"
},
"glass.Container": {
source: "extends: 'Observable'
properties:
watch: ->
unwatch: ->
",
input: "runtime\\glass\\Container.coffee",
content: {
extends: ["glass.Observable"],
properties: {
watch: {
value: function() {},
name: "watch"
},
unwatch: {
value: function() {},
name: "unwatch"
}
},
name: "Container",
path: "glass.Container",
namespace: "glass",
require: {
glass: "glass",
"glass.Observable": "Observable"
},
import: {},
implements: {
"glass.Container": true,
"glass.Observable": true
},
uri: "global:/glass/Container"
},
output: "www\\js\\glass\\Container.js"
},
"glass.Expression._parser": {
source: "{
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e,array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++)
array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
}
start = expression
expression = conditional
conditional = e:or args:(\"?\" b:expression \":\" c:expression {return [b,c];})* {
while (args.length > 0) {
e = expr(\"?:\", [e].concat(args.pop()));
}
return e;
}
or = a:and b:((\"or\") and)* { return joinLeft(a,b); }
and = a:equality b:((\"and\") equality)* { return joinLeft(a,b); }
equality = a:rel b:((\"==\" / \"!=\") rel)* { return joinLeft(a,b); }
rel = a:sum b:((\"<=\" / \">=\" / \"<\" / \">\") sum)* { return joinLeft(a,b); }
sum = a:product b:((\"+\" / \"-\") product)* { return joinLeft(a,b); }
product = a:not b:((\"*\" / \"div\" / \"mod\") not)* { return joinLeft(a,b); }
not = ops:(s op:(\"!\" / \"~\" / \"+\" / \"-\") { return op; })* b:primary { return unaryRight(ops,b); }
primary = s a:(group / literal / path) s { return a; }
group = \"(\" a:expression \")\" { return a; }
literal = s a:(boolean / number / string / array / object) s { return a; }
boolean = a:(\"true\" / \"false\") { return a == \"true\"; }
number = a:([0-9]+ (\".\" [0-9]+)?) { return parseFloat(toString(a)); }
hex = [a-fA-F0-9]
// as per JSON http://www.json.org
string = a:( '\"' (
[\\u0000-\\u0021\\u0023-\\u005c\\u005e-\\uffff] // all unicode chars except \\ and \"
/ (\"\\\\\" (\"\\\"\" / \"\\\\\" / \"\\/\" / \"b\" / \"f\" / \"n\" / \"r\" / \"t\" / (\"u\" hex hex hex hex)))
)* '\"' )
{ return JSON.parse(toString(a)); }
array = \"[\" a:values \"]\" { return expr(\"array\", a); }
values = first:expression? args:(\",\" b:expression {return b;})* {
if (first != \"\") { args.unshift(first); } return args;
}
object = \"{\" a:keyvalues \"}\" { return expr(\"object\", a); }
keyvalue = s a:string s \":\" b:expression { return [a,b]; }
keyvalues = first:keyvalue? rest:(\",\" b:keyvalue {return b;})* {
if (first) { rest.unshift(first); } return rest;
}
ref = a:(\"//\" / \"/\" / \"$\" / \"**\" / \"*\" / \"..\" / \".\") b:slashProperty? {
e = expr(a); if (b) { b.args.unshift(e); e = b; } return e;
}
/ a:id { return expr(\"ref\", [a]); }
id = a:[a-z_]+ b:[a-z_0-9]* { return a.join('') + b.join(''); }
property = \"/\" a:slashProperty { return a; }
/ \"{\" a:expression \"}\" { return expr(\"{}\", [a]); } // locally scoped expression
/ \"[\" a:expression \"]\" { return expr(\"[]\", [a]); } // predicate
slashProperty = a:(id/number/string) { return expr(\"/\", [a]); }
/ a:(\"..\" / \"*\") { return expr(a, []); }
s \"space\" = [ ]* { return ''; }
path = a:root b:step* {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
}
root = a:implicitDotRoot b:dotStep? { return joinPath(a,b); }
/ explicitDotRoot
step = \".\" a:dotStep { return a; }
/ noDotStep
implicitDotRoot = \"/\" { return expr(\"root\"); }
/ \"@\" { return expr(\"this\"); }
/ \".\" a:\".\"+ { return expr(\"ancestor\", [a.length]); }
explicitDotRoot = a:id { return expr(\"ref\", [a]); }
/ \"*\" { return expr(\"values\", []); }
dotStep = a:(id / string / number) { return expr(\"get\", [a]); }
/ \"*\" { return expr(\"values\", []); }
noDotStep = \"{\" a:expression \"}\" { return expr(\"eval\", [a]); }
/ \"[\" a:expression \"]\" { return expr(\"pred\", [a]); }
/ \"(\" a:values \")\" { return expr(\"call\", [a]); }
",
input: "runtime\\glass\\Expression\\_parser.pegjs",
content: {
value: {
parse: function(input, startRule) {
var parseFunctions = {
"conditional": parse_conditional,
"or": parse_or,
"and": parse_and,
"equality": parse_equality,
"rel": parse_rel,
"sum": parse_sum,
"product": parse_product,
"not": parse_not,
"primary": parse_primary,
"group": parse_group,
"literal": parse_literal,
"boolean": parse_boolean,
"number": parse_number,
"hex": parse_hex,
"string": parse_string,
"array": parse_array,
"values": parse_values,
"object": parse_object,
"keyvalue": parse_keyvalue,
"keyvalues": parse_keyvalues,
"ref": parse_ref,
"id": parse_id,
"property": parse_property,
"slashProperty": parse_slashProperty,
"s": parse_s,
"path": parse_path,
"root": parse_root,
"step": parse_step,
"implicitDotRoot": parse_implicitDotRoot,
"explicitDotRoot": parse_explicitDotRoot,
"dotStep": parse_dotStep,
"noDotStep": parse_noDotStep
};
if (startRule !== undefined) {
if (parseFunctions[startRule] === undefined) {
throw new Error("Invalid rule name: " + quote(startRule) + ".");
}
} else {
startRule = "conditional";
}
var pos = 0;
var reportFailures = 0;
var rightmostFailuresPos = 0;
var rightmostFailuresExpected = [];
function padLeft(input, padding, length) {
var result = input;
var padLength = length - input.length;
for (var i = 0; i < padLength; i++) {
result = padding + result;
}
return result;
}
function escape(ch) {
var charCode = ch.charCodeAt(0);
var escapeChar;
var length;
if (charCode <= 0xFF) {
escapeChar = 'x';
length = 2;
} else {
escapeChar = 'u';
length = 4;
}
return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
}
function matchFailed(failure) {
if (pos < rightmostFailuresPos) {
return;
}
if (pos > rightmostFailuresPos) {
rightmostFailuresPos = pos;
rightmostFailuresExpected = [];
}
rightmostFailuresExpected.push(failure);
}
function parse_conditional() {
var result0, result1, result2, result3, result4, result5;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_or();
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, e, args) {
while (args.length > 0) {
e = expr("?:", [e].concat(args.pop()));
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_or() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_and();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_and() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_equality();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_equality() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_rel();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_rel() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_sum();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_sum() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_product();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_product() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_not();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_not() {
var result0, result1, result2;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = [];
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
while (result1 !== null) {
result0.push(result1);
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
}
if (result0 !== null) {
result1 = parse_primary();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, ops, b) {
return unaryRight(ops, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_primary() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_group();
if (result1 === null) {
result1 = parse_literal();
if (result1 === null) {
result1 = parse_path();
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_group() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_literal() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_boolean();
if (result1 === null) {
result1 = parse_number();
if (result1 === null) {
result1 = parse_string();
if (result1 === null) {
result1 = parse_array();
if (result1 === null) {
result1 = parse_object();
}
}
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_boolean() {
var result0;
var pos0;
pos0 = pos;
if (input.substr(pos, 4) === "true") {
result0 = "true";
pos += 4;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"true\"");
}
}
if (result0 === null) {
if (input.substr(pos, 5) === "false") {
result0 = "false";
pos += 5;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"false\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a == "true";
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_number() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
pos2 = pos;
if (input.charCodeAt(pos) === 46) {
result1 = ".";
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result1 !== null) {
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result3 !== null) {
result2 = [];
while (result3 !== null) {
result2.push(result3);
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result2 = null;
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos2;
}
} else {
result1 = null;
pos = pos2;
}
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return parseFloat(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_hex() {
var result0;
if (/^[a-fA-F0-9]/.test(input.charAt(pos))) {
result0 = input.charAt(pos);
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("[a-fA-F0-9]");
}
}
return result0;
}
function parse_string() {
var result0, result1, result2, result3, result4, result5, result6, result7;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 34) {
result0 = "\"";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result0 !== null) {
result1 = [];
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
}
if (result1 !== null) {
if (input.charCodeAt(pos) === 34) {
result2 = "\"";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return JSON.parse(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_array() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("array", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_values() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_conditional();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, args) {
if (first != "") {
args.unshift(first);
}
return args;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_object() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_keyvalues();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("object", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalue() {
var result0, result1, result2, result3, result4;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_string();
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
if (input.charCodeAt(pos) === 58) {
result3 = ":";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result3 !== null) {
result4 = parse_conditional();
if (result4 !== null) {
result0 = [result0, result1, result2, result3, result4];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return [a, b];
})(pos0, result0[1], result0[4]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalues() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_keyvalue();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, rest) {
if (first) {
rest.unshift(first);
}
return rest;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_ref() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.substr(pos, 2) === "//") {
result0 = "//";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"//\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 36) {
result0 = "$";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"$\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "**") {
result0 = "**";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"**\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
}
}
}
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
e = expr(a);
if (b) {
b.args.unshift(e);
e = b;
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_id() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
result1 = [];
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return a.join('') + b.join('');
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_property() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("{}", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("[]", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_slashProperty() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_number();
if (result0 === null) {
result0 = parse_string();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("/", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(a, []);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_s() {
var result0, result1;
var pos0;
reportFailures++;
pos0 = pos;
result0 = [];
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
while (result1 !== null) {
result0.push(result1);
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
}
if (result0 !== null) {
result0 = (function(offset) {
return '';
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
reportFailures--;
if (reportFailures === 0 && result0 === null) {
matchFailed("space");
}
return result0;
}
function parse_path() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_root();
if (result0 !== null) {
result1 = [];
result2 = parse_step();
while (result2 !== null) {
result1.push(result2);
result2 = parse_step();
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_root() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_implicitDotRoot();
if (result0 !== null) {
result1 = parse_dotStep();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinPath(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_explicitDotRoot();
}
return result0;
}
function parse_step() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
result1 = parse_dotStep();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_noDotStep();
}
return result0;
}
function parse_implicitDotRoot() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("root");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 64) {
result0 = "@";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"@\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("this");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result2 !== null) {
result1 = [];
while (result2 !== null) {
result1.push(result2);
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
} else {
result1 = null;
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ancestor", [a.length]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_explicitDotRoot() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_dotStep() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_string();
if (result0 === null) {
result0 = parse_number();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("get", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_noDotStep() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("eval", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("pred", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("call", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function cleanupExpected(expected) {
expected.sort();
var lastExpected = null;
var cleanExpected = [];
for (var i = 0; i < expected.length; i++) {
if (expected[i] !== lastExpected) {
cleanExpected.push(expected[i]);
lastExpected = expected[i];
}
}
return cleanExpected;
}
function computeErrorPosition() {
/*
* The first idea was to use |String.split| to break the input up to the
* error position along newlines and derive the line and column from
* there. However IE's |split| implementation is so broken that it was
* enough to prevent it.
*/
var line = 1;
var column = 1;
var seenCR = false;
for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
var ch = input.charAt(i);
if (ch === "
") {
if (!seenCR) {
line++;
}
column = 1;
seenCR = false;
} else if (ch === "
" || ch === "\u2028" || ch === "\u2029") {
line++;
column = 1;
seenCR = true;
} else {
column++;
seenCR = false;
}
}
return {
line: line,
column: column
};
}
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e, array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++) array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
var result = parseFunctions[startRule]();
/*
* The parser is now in one of the following three states:
*
* 1. The parser successfully parsed the whole input.
*
* - |result !== null|
* - |pos === input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 2. The parser successfully parsed only a part of the input.
*
* - |result !== null|
* - |pos < input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 3. The parser did not successfully parse any part of the input.
*
* - |result === null|
* - |pos === 0|
* - |rightmostFailuresExpected| contains at least one failure
*
* All code following this comment (including called functions) must
* handle these states.
*/
if (result === null || pos !== input.length) {
var offset = Math.max(pos, rightmostFailuresPos);
var found = offset < input.length ? input.charAt(offset) : null;
var errorPosition = computeErrorPosition();
throw new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column);
}
return result;
},
toSource: function() {
return this._source;
},
SyntaxError: function(expected, found, offset, line, column) {
function buildMessage(expected, found) {
var expectedHumanized, foundHumanized;
switch (expected.length) {
case 0:
expectedHumanized = "end of input";
break;
case 1:
expectedHumanized = expected[0];
break;
default:
expectedHumanized = expected.slice(0, expected.length - 1).join(", ") + " or " + expected[expected.length - 1];
}
foundHumanized = found ? quote(found) : "end of input";
return "Expected " + expectedHumanized + " but " + foundHumanized + " found.";
}
this.name = "SyntaxError";
this.expected = expected;
this.found = found;
this.message = buildMessage(expected, found);
this.offset = offset;
this.line = line;
this.column = column;
}
},
name: "_parser",
path: "glass.Expression._parser",
namespace: "glass.Expression",
require: {
"glass.Expression": "Expression"
},
import: {
"glass.values": "values"
},
uri: "global:/glass/Expression/_parser"
},
output: "www\\js\\glass\\Expression\\_parser.js"
},
"glass.allTests": {
content: {
path: "glass.allTests",
name: "allTests",
namespace: "glass",
import: {
glass: "glass",
"glass.Expression": "glass_Expression",
"glass.JSONMergePatch": "glass_JSONMergePatch",
"glass.JSONPointer": "glass_JSONPointer",
"glass.Observable": "glass_Observable",
"glass.Component": "glass_Component"
},
value: function anonymous(callback) {
if (callback == null) {
callback = function(path, result) {
if (result == null) {
console.log("\033[92mPass\033[0m: " + path + "");
} else {
console.log("\033[91mFail\033[0m: " + path + "");
console.log(result.stack || result);
}
}
}
function singleTest(path, test) {
if (test == null) {
callback(path, "test not found");
return;
} else if (typeof test == 'object') {
for (var key in test) singleTest(path + '.' + key, test[key]);
return;
}
try {
callback(path, test());
} catch(e) {
callback(path, e);
}
}
singleTest("glass", glass.test);
singleTest("glass.Expression", glass_Expression.test);
singleTest("glass.JSONMergePatch", glass_JSONMergePatch.test);
singleTest("glass.JSONPointer", glass_JSONPointer.test);
singleTest("glass.Observable", glass_Observable.test);
singleTest("glass.Component", glass_Component.test);
}
},
isLast: true,
output: "www\\js\\glass\\allTests.js"
}
},
output: {
"www\\js\\String.js": "(function() {
var global = (function() {
return this;
})();
if (String.prototype.startsWith == null) {
Object.defineProperty(String.prototype, \"startsWith\", {
value: function(s) {
return this.slice(0, s.length) === s;
},
name: \"startsWith\"
});
}
if (String.prototype.endsWith == null) {
Object.defineProperty(String.prototype, \"endsWith\", {
value: function(s) {
return this.slice( - s.length) === s;
},
name: \"endsWith\"
});
}
if (String.prototype.contains == null) {
Object.defineProperty(String.prototype, \"contains\", {
value: function(s) {
return this.indexOf(s) >= 0;
},
name: \"contains\"
});
}
if (String.prototype.toArray == null) {
Object.defineProperty(String.prototype, \"toArray\", {
value: function() {
return this.split('');
},
name: \"toArray\"
});
}
String._init_ = function() {
delete String._init_;
}
}).call()",
"www\\js\\glass.js": "(function() {
var global = (function() {
return this;
})();
var JSONMergePatch; // assigned during _init_
var isFunction; // assigned during _init_
var isString; // assigned during _init_
var isArray; // assigned during _init_
var isBoolean; // assigned during _init_
var isNumber; // assigned during _init_
var isDate; // assigned during _init_
var values; // assigned during _init_
var patch; // assigned during _init_
var _getStackLocationInfo; // assigned during _init_
var _throwAssertionFailure; // assigned during _init_
var _dumpFile; // assigned during _init_
var assertEquals; // assigned during _init_
var glass = this.glass = {
isFunction: function(object) {
return (object != null) && typeof object === 'function';
},
isString: function(object) {
return (object != null ? object.constructor: void 0) === String;
},
isArray: function(object) {
return Array.isArray(object);
},
isBoolean: function(object) {
return (object != null) && typeof object === 'boolean';
},
isNumber: function(object) {
return (object != null) && typeof object === 'number';
},
isObject: function(object) {
return typeof object === 'object';
},
isPlainObject: function(object) {
return (object != null ? object.constructor: void 0) === Object;
},
isPrototype: function(object) {
return (object != null) && object === object.constructor.prototype;
},
isDate: function(object) {
return (object != null ? object.constructor: void 0) === Date;
},
isPrimitive: function(object) {
return isString(object) || isBoolean(object) || isNumber(object) || isDate(object);
},
isPrivate: function(property) {
return (property != null ? property[0] : void 0) === '_';
},
values: function(object) {
var key, value, _results;
_results = [];
for (key in object) {
value = object[key];
_results.push(value);
}
return _results;
},
patch: function() {
var patch, pathAndPatch, target;
target = arguments[0],
pathAndPatch = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
patch = JSONMergePatch.create.apply(null, pathAndPatch);
if (isFunction(target != null ? target.patch: void 0)) {
return target.patch(patch);
} else {
return glass.JSONMergePatch.apply(target, patch);
}
},
_getStackLocationInfo: function(e, depth) {
var line, match, _ref;
line = (_ref = e.stack) != null ? _ref.split('
')[depth] : void 0;
if (line == null) {
return null;
}
match = /\\(([\\w\\W]*?):(\\d+):(\\d+)\\)/.exec(line);
return {
file: match[1],
line: parseInt(match[2]),
column: parseInt(match[3])
};
},
_throwAssertionFailure: function(message) {
var info;
try {
throw new Error(\"Assertion failed: \" + message);
} catch(e) {
info = _getStackLocationInfo(e, 3);
if (info != null) {
_dumpFile(info.file, info.line - 2, info.line + 2, info.line);
}
throw e;
}
},
_dumpFile: function(file, from, to, highlight) {
var content, fs, line, lineNumber, lines, num, number, _i, _len;
if (from == null) {
from = 1;
}
fs = require('fs');
if (fs == null) {
return;
}
try {
content = fs.readFileSync(file).toString();
} catch(e) {
content = \"Source not found: \" + e;
}
console.log('------------------------------------------------');
console.log(file);
console.log('------------------------------------------------');
number = 1;
if (content != null) {
lines = content.split(/
|
/);
if (to == null) {
to = lines.length;
}
for (_i = 0, _len = lines.length; _i < _len; _i++) {
line = lines[_i];
lineNumber = number++;
if (lineNumber >= from && lineNumber <= to) {
num = String(lineNumber);
while (num.length < 3) {
num += ' ';
}
if (lineNumber === highlight) {
console.log(\"\\033[91m\" + num + \": \" + line + \"\\033[0m\");;
} else {
console.log(num + \": \" + line);;
}
}
}
}
return console.log('------------------------------------------------');
},
assert: function(a) {
if (!a) {
return _throwAssertionFailure(JSON.stringify(a));
}
},
assertTrue: function(a) {
if (a !== true) {
return _throwAssertionFailure(JSON.stringify(a) + \" != true\");
}
},
assertEquals: function(a, b) {
if (JSON.stringify(a) !== JSON.stringify(b)) {
return _throwAssertionFailure(JSON.stringify(a) + ' != ' + JSON.stringify(b));
}
},
getId: (function() {
var counter;
counter = 0;
return function(a) {
var _ref;
if (a === null) {
return '__null__';
}
if (a === void 0) {
return '__undefined__';
}
if (typeof a === 'object' || typeof a === 'function') {
return (_ref = a.id) != null ? _ref: a.id = '__' + (counter++) + '__';
}
return a.toString();
};
})(),
getType: function(path) {
var array, step, value, _i, _len;
array = isArray(path) ? path: path.split('.');
value = global;
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
if (!isFunction(value)) {
throw new Error(\"Type not found: \" + path);
}
return value;
},
test: {
values: function() {
return assertEquals(values({
a: 1,
b: 3,
c: 2
}), [1, 3, 2]);
},
patch: function() {
var x;
x = {
a: {
foo: 1,
bar: 3
},
b: 2
};
patch(x, 'a', 'foo', 5);
return assertEquals(x.a.foo, 5);
}
},
path: \"glass\",
uri: \"global:/glass\"
};
glass._init_ = function() {
JSONMergePatch = global.glass.JSONMergePatch;
isFunction = global.glass.isFunction;
isString = global.glass.isString;
isArray = global.glass.isArray;
isBoolean = global.glass.isBoolean;
isNumber = global.glass.isNumber;
isDate = global.glass.isDate;
values = global.glass.values;
patch = global.glass.patch;
_getStackLocationInfo = global.glass._getStackLocationInfo;
_throwAssertionFailure = global.glass._throwAssertionFailure;
_dumpFile = global.glass._dumpFile;
assertEquals = global.glass.assertEquals;
delete glass._init_;
}
}).call()",
"www\\js\\glass\\Expression.js": "(function() {
var global = (function() {
return this;
})();
var glass = this;
var _parser; // assigned during _init_
var values; // assigned during _init_
var Expression = this.Expression = function Expression(op, args) {
this.op = op;
if (args != null) {
this.args = args;
}
return this;
};
Expression.properties = {
op: {
type: \"string\",
name: \"op\",
writable: true
},
args: {
type: \"array\",
name: \"args\",
writable: true
}
};
Expression.test = function() {
var expected, fs, parser, parserSource, peg, result, tests, text;
return;
peg = require('pegjs');
fs = require('fs');
parserSource = fs.readFileSync('runtime/glass/Expression/_parser.pegjs', 'utf8');
parser = peg.buildParser(parserSource);
tests = {
\"a.b.c\": {
op: \"get\",
args: [{
op: \"get\",
args: [{
op: \"ref\",
args: [\"a\"]
},
\"b\"]
},
\"c\"]
},
\"a.1\": {
op: \"get\",
args: [{
op: \"ref\",
args: [\"a\"]
},
1]
},
\"true\": true,
\"false\": false,
\"45.8\": 45.8,
\"(45.8)\": 45.8,
\"((45.8))\": 45.8,
\"alpha\": {
op: \"ref\",
args: [\"alpha\"]
},
\"35 + true * 2\": {
op: \"+\",
args: [35, {
op: \"*\",
args: [true, 2]
}]
},
\" 5 * ( 2 + 2 ) \": {
op: \"*\",
args: [5, {
op: \"+\",
args: [2, 2]
}]
},
\" ! ! true\": {
op: \"!\",
args: [{
op: \"!\",
args: [true]
}]
},
\"5 + -x\": {
op: \"+\",
args: [5, {
op: \"-\",
args: [{
op: \"ref\",
args: [\"x\"]
}]
}]
},
\"true == 5 >= 2\": {
op: \"==\",
args: [true, {
op: \">=\",
args: [5, 2]
}]
},
\"1 or 2 and 3\": {
op: \"or\",
args: [1, {
op: \"and\",
args: [2, 3]
}]
},
\"1 ? 2 : 3\": {
op: \"?:\",
args: [1, 2, 3]
},
\"1 ? 2 : 3 ? 4 : 5\": {
op: \"?:\",
args: [1, 2, {
op: \"?:\",
args: [3, 4, 5]
}]
},
\"a()(1,2)\": {
op: \"call\",
args: [{
op: \"call\",
args: [{
op: \"ref\",
args: [\"a\"]
},
[]]
},
[1, 2]]
},
\"@\": {
op: \"this\"
},
\"@foo\": {
op: \"get\",
args: [{
op: \"this\"
},
\"foo\"]
},
'\"hello\"': \"hello\",
'\"\\\\t\\
\\
\\\\b\\\\\\\\foo\\\\\\/\"': \"\\t
\\b\\\\foo\\/\",
\"[]\": {
op: \"array\",
args: []
},
\"[1,2]\": {
op: \"array\",
args: [1, 2]
},
\"[1+2]\": {
op: \"array\",
args: [{
op: \"+\",
args: [1, 2]
}]
},
\"{}\": {
op: \"object\",
args: []
},
'{\"a\":2}': {
op: \"object\",
args: [[\"a\", 2]]
},
'{\"a\":2,\"b\":1+2}': {
op: \"object\",
args: [[\"a\", 2], [\"b\", {
op: \"+\",
args: [1, 2]
}]]
},
'@\"alpha\"': {
op: \"get\",
args: [{
op: \"this\"
},
\"alpha\"]
},
'*': {
op: \"values\",
args: []
},
'*.*': {
op: \"values\",
args: [{
op: \"values\",
args: []
}]
},
\"foo.*\": {
op: \"values\",
args: [{
op: \"ref\",
args: [\"foo\"]
}]
},
\"..\": {
op: \"ancestor\",
args: [1]
},
\"...\": {
op: \"ancestor\",
args: [2]
},
\"@*{1+2}\": {
op: \"eval\",
args: [{
op: \"values\",
args: [{
op: \"this\"
}]
},
{
op: \"+\",
args: [1, 2]
}]
},
\"/\": {
op: \"root\"
},
\"/foo\": {
op: \"get\",
args: [{
op: \"root\"
},
\"foo\"]
},
\"/*\": {
op: \"values\",
args: [{
op: \"root\"
}]
}
};
for (text in tests) {
expected = tests[text];
result = parser.parse(text);
if (JSON.stringify(result) === JSON.stringify(expected)) {
console.log('Pass: ' + text);
} else {
console.log(text, JSON.stringify(result));
}
}
};
Expression.path = \"glass.Expression\";
Expression.implements = {
\"glass.Expression\": true
};
Expression.uri = \"global:/glass/Expression\";
Object.defineProperties(Expression.prototype, Expression.properties);
Expression._init_ = function() {
_parser = global.glass.Expression._parser;
values = global.glass.values;
delete Expression._init_;
}
}).call(glass)",
"www\\js\\glass\\JSONMergePatch.js": "(function() {
var global = (function() {
return this;
})();
var glass = this;
var apply; // assigned during _init_
var create; // assigned during _init_
var isPlainObject; // assigned during _init_
var isPrimitive; // assigned during _init_
var patch; // assigned during _init_
var assertEquals; // assigned during _init_
var JSONMergePatch = this.JSONMergePatch = {
apply: function(target, patch) {
var key, value;
if ((target != null) && target !== patch && isPlainObject(patch) && !isPrimitive(target)) {
for (key in patch) {
value = patch[key];
if (value === void 0) {
delete target[key];
} else {
target[key] = apply(target[key], patch[key]);
}
}
return target;
} else {
return patch;
}
},
create: function() {
var arg, current, i, last, result, _i, _len;
if (arguments.length === 1) {
return arguments[0];
}
result = {};
current = result;
for (i = _i = 0, _len = arguments.length; _i < _len; i = ++_i) {
arg = arguments[i];
if (! (i + 1 < arguments.length)) {
continue;
}
last = i + 2 === arguments.length;
current = current[arg] = last ? arguments[arguments.length - 1] : {};
}
return result;
},
test: function() {
assertEquals({
a: {
b: 12
}
},
create('a', 'b', 12));
return assertEquals({
a: 3
},
apply({
a: 1,
b: 2
},
{
a: 3,
b: void 0
}));
},
path: \"glass.JSONMergePatch\",
uri: \"global:/glass/JSONMergePatch\"
};
JSONMergePatch._init_ = function() {
apply = global.glass.JSONMergePatch.apply;
create = global.glass.JSONMergePatch.create;
isPlainObject = global.glass.isPlainObject;
isPrimitive = global.glass.isPrimitive;
patch = global.glass.patch;
assertEquals = global.glass.assertEquals;
delete JSONMergePatch._init_;
}
}).call(glass)",
"www\\js\\glass\\JSONPointer.js": "(function() {
var global = (function() {
return this;
})();
var glass = this;
var _decodeStep; // assigned during _init_
var _getLastStep; // assigned during _init_
var _getParent; // assigned during _init_
var toArray; // assigned during _init_
var get; // assigned during _init_
var set; // assigned during _init_
var assertEquals; // assigned during _init_
var JSONPointer = this.JSONPointer = {
_decodeStep: function(step) {
return step.replace(/~1/g, '/').replace(/~0/g, '~');
},
_getLastStep: function(pointer) {
return _decodeStep(pointer.substring(pointer.lastIndexOf('/') + 1));
},
_getParent: function(pointer) {
if (! (pointer != null ? pointer.length: void 0)) {
return null;
} else {
return pointer.substring(0, pointer.lastIndexOf('/'));
}
},
toArray: function(pointer) {
var step, _i, _len, _ref, _results;
_ref = pointer.substring(1).split('/');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
step = _ref[_i];
_results.push(_decodeStep(step));
}
return _results;
},
get: function(doc, pointer) {
var path, step, value, _i, _len;
value = doc;
if (pointer.length) {
path = toArray(pointer);
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
}
return value;
},
set: function(doc, pointer, value) {
var lastStep, parent, parentPointer;
parentPointer = _getParent(pointer);
if (parentPointer != null) {
parent = get(doc, parentPointer);
lastStep = _getLastStep(pointer);
parent[lastStep] = value;
}
return value;
},
test: function() {
var doc;
assertEquals(_getParent(\"/a/b/c\"), \"/a/b\");
assertEquals(_getParent(\"/a\"), \"\");
assertEquals(_getParent(\"\"), null);
assertEquals(_getLastStep(\"/a/b/c\"), \"c\");
assertEquals(_getLastStep(\"/a~0~1\"), \"a~/\");
assertEquals(_getLastStep(\"\"), \"\");
doc = {
\"foo\": [\"bar\", \"baz\"],
\"\": 0,
\"a/b\": 1,
\"c%d\": 2,
\"e^f\": 3,
\"g|h\": 4,
\"i\\\\j\": 5,
\"k\\\"l\": 6,
\" \": 7,
\"m~n\": 8
};
assertEquals(get(doc, \"\"), doc);
assertEquals(get(doc, \"/foo\"), [\"bar\", \"baz\"]);
assertEquals(get(doc, \"/foo/0\"), \"bar\");
assertEquals(get(doc, \"/\"), 0);
assertEquals(get(doc, \"/a~1b\"), 1);
assertEquals(get(doc, \"/c%d\"), 2);
assertEquals(get(doc, \"/e^f\"), 3);
assertEquals(get(doc, \"/g|h\"), 4);
assertEquals(get(doc, \"/i\\\\j\"), 5);
assertEquals(get(doc, \"/k\\\"l\"), 6);
assertEquals(get(doc, \"/ \"), 7);
assertEquals(get(doc, \"/m~0n\"), 8);
assertEquals(set(doc, \"/\", 10), 10);
assertEquals(doc[\"\"], 10);
assertEquals(set(doc, \"/foo/0\", 10), 10);
return assertEquals(doc.foo[0], 10);
},
path: \"glass.JSONPointer\",
uri: \"global:/glass/JSONPointer\"
};
JSONPointer._init_ = function() {
_decodeStep = global.glass.JSONPointer._decodeStep;
_getLastStep = global.glass.JSONPointer._getLastStep;
_getParent = global.glass.JSONPointer._getParent;
toArray = global.glass.JSONPointer.toArray;
get = global.glass.JSONPointer.get;
set = global.glass.JSONPointer.set;
assertEquals = global.glass.assertEquals;
delete JSONPointer._init_;
}
}).call(glass)",
"www\\js\\glass\\Observable.js": "(function() {
var global = (function() {
return this;
})();
var glass = this;
var JSONMergePatch; // assigned during _init_
var isFunction; // assigned during _init_
var isPrivate; // assigned during _init_
var values; // assigned during _init_
var patch; // assigned during _init_
var assert; // assigned during _init_
var assertEquals; // assigned during _init_
var getId; // assigned during _init_
var Observable = this.Observable = function Observable(properties) {
var key;
if (properties != null) {
for (key in properties) {
this[key] = properties[key];
}
}
}
Observable.properties = {
is: {
value: function(type) {
var _ref;
return this.constructor[\"implements\"][(_ref = type.path) != null ? _ref: type] === true;
},
name: \"is\"
},
watchers: {
serializable: false,
name: \"watchers\",
writable: true
},
watch: {
value: function(property, watcher) {
var id, _this = this;
if (isFunction(property)) {
watcher = property;
property = '';
}
id = getId(watcher);
this.patch('watchers', property, id, watcher);
return function() {
return _this.patch('watchers', property, getId(watcher), void 0);
};
},
name: \"watch\"
},
patch: {
value: function(change) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
try {
JSONMergePatch.apply(this, change);
} catch(e) {
console.log(e);
} finally {
this.notify(change);
}
},
name: \"patch\"
},
notify: {
value: function(change) {
var changeArg, id, property, watcher, watchers, _ref;
if (this.watchers != null) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
_ref = this.watchers;
for (property in _ref) {
watchers = _ref[property];
if (property.length === 0 || change.hasOwnProperty(property)) {
changeArg = property.length === 0 ? change: change[property];
for (id in watchers) {
watcher = watchers[id];
watcher(this, changeArg);
}
}
}
}
},
name: \"notify\"
},
toJSON: {
value: function() {
var name, property, value, values, _ref;
values = {
\"class\": this.constructor.path
};
_ref = this.constructor.properties;
for (name in _ref) {
property = _ref[name];
value = this[name];
if (property.serializable !== false && !isFunction(value)) {
values[name] = value;
}
}
if (this.constructor.additionalProperties !== false) {
for (name in this) {
if (!__hasProp.call(this, name)) continue;
value = this[name];
if (!isPrivate(name)) {
values[name] = value;
}
}
}
return values;
},
name: \"toJSON\"
},
toString: {
value: function() {
return this.toJSON();
},
name: \"toString\"
}
};
Observable.test = {
toJSON: function() {
var a;
a = new Observable;
a.x = 12;
a.y = function() {};
a.z = true;
return assertEquals(a, {
\"class\": 'glass.Observable',
x: 12,
z: true
});
},
watchAll: function() {
var a, unwatch, watchArgs, watcher, _ref, _ref1;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch(watcher);
assert(watchArgs[0] === a);
assert(((_ref = watchArgs[1]) != null ? (_ref1 = _ref.watchers) != null ? _ref1[\"\"] : void 0 : void 0) != null);
watchArgs.length = 0;
a.patch(\"a\", \"b\", 3);
assertEquals(a.a, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
a: {
b: 3
}
});
unwatch();
assertEquals(a.watchers[\"\"], {});
watchArgs.length = 0;
a.patch(\"a\", \"b\", 3);
return assert(watchArgs.length === 0);
},
watchProperty: function() {
var a, unwatch, watchArgs, watcher;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch(\"foo\", watcher);
assert(watchArgs.length === 0);
a.patch(\"foo\", \"b\", 3);
assertEquals(a.foo, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
b: 3
});
watchArgs.length = 0;
a.patch(\"a\", \"b\", 3);
assert(watchArgs.length === 0);
unwatch();
watchArgs.length = 0;
a.patch(\"foo\", \"b\", 4);
return assert(watchArgs.length === 0);
}
};
Observable.path = \"glass.Observable\";
Observable.implements = {
\"glass.Observable\": true
};
Observable.uri = \"global:/glass/Observable\";
Object.defineProperties(Observable.prototype, Observable.properties);
Observable._init_ = function() {
JSONMergePatch = global.glass.JSONMergePatch;
isFunction = global.glass.isFunction;
isPrivate = global.glass.isPrivate;
values = global.glass.values;
patch = global.glass.patch;
assert = global.glass.assert;
assertEquals = global.glass.assertEquals;
getId = global.glass.getId;
delete Observable._init_;
}
}).call(glass)",
"www\\js\\glass\\Component.js": "(function() {
var global = (function() {
return this;
})();
var glass = this;
var Observable = global.glass.Observable;
var Observable; // assigned during _init_
var isString; // assigned during _init_
var patch; // assigned during _init_
var assert; // assigned during _init_
var assertEquals; // assigned during _init_
var getId; // assigned during _init_
var Component = this.Component = function Component(properties) {
var id;
this.patch(properties);
if (this.parent) {
id = getId(this);
patch(this.parent, id, this);
}
return this;
};
Component.properties = {
id: {
description: \"string which uniquely identifies this component within its parent\",
type: \"string\",
name: \"id\",
writable: true
},
parent: {
description: \"the object that contains this component\",
serializable: false,
type: \"object\",
name: \"parent\",
writable: true
},
disposed: {
value: false,
name: \"disposed\",
writable: true
},
dispose: {
value: function() {
return this.patch('disposed', true);
},
name: \"dispose\"
},
notify: {
value: function(change) {
var child, id;
Observable.prototype.notify.apply(this, arguments);
if (change != null ? change.disposed: void 0) {
for (id in this) {
child = this[id];
if ((child != null ? child.parent: void 0) === this) {
if (typeof child.dispose === \"function\") {
child.dispose();
}
}
}
if (this.id && this.parent) {
patch(this.parent, this.id, void 0);
}
}
},
name: \"notify\"
}
};
Component.test = {
lifecycle: function() {
var child, parent;
parent = new Component;
assert(!(parent.id != null));
assert(!(parent.parent != null));
child = new Component({
parent: parent
});
assert(isString(child.id));
assert(parent === child.parent);
assert(parent[child.id] === child);
assert(parent.hasOwnProperty(child.id));
parent.dispose();
assert(child.disposed === true);
return assert(!parent.hasOwnProperty(child.id));
},
nonEnumerability: function() {
var key, visibleKeys;
visibleKeys = (function() {
var _results;
_results = [];
for (key in new Component) {
_results.push(key);
}
return _results;
})();
return assertEquals(visibleKeys, []);
}
};
Component.path = \"glass.Component\";
Component.implements = {
\"glass.Component\": true,
\"glass.Observable\": true
};
Component.uri = \"global:/glass/Component\";
(function() {
var baseTypes = [Observable];
var i, j, baseType, a, b;
for (i = 0; i < baseTypes.length; i++) {
baseType = baseTypes[i];
for (key in baseType.properties) {
a = Component.properties[key];
b = baseType.properties[key];
if (a != null && b != null && a.constructor === Object && b.constructor === Object) {
for (j in b) {
if (!a.hasOwnProperty(j)) a[j] = b[j];
}
} else if (!Component.properties.hasOwnProperty(key)) {
Component.properties[key] = b;
}
}
}
})();
Object.defineProperties(Component.prototype, Component.properties);
Component._init_ = function() {
Observable = global.glass.Observable;
isString = global.glass.isString;
patch = global.glass.patch;
assert = global.glass.assert;
assertEquals = global.glass.assertEquals;
getId = global.glass.getId;
delete Component._init_;
}
}).call(glass)",
"www\\js\\glass\\Container.js": "(function() {
var global = (function() {
return this;
})();
var glass = this;
var Observable = global.glass.Observable;
var Container = this.Container = function Container(properties) {
var key;
if (properties != null) {
for (key in properties) {
this[key] = properties[key];
}
}
}
Container.properties = {
watch: {
value: function() {},
name: \"watch\"
},
unwatch: {
value: function() {},
name: \"unwatch\"
}
};
Container.path = \"glass.Container\";
Container.implements = {
\"glass.Container\": true,
\"glass.Observable\": true
};
Container.uri = \"global:/glass/Container\";
(function() {
var baseTypes = [Observable];
var i, j, baseType, a, b;
for (i = 0; i < baseTypes.length; i++) {
baseType = baseTypes[i];
for (key in baseType.properties) {
a = Container.properties[key];
b = baseType.properties[key];
if (a != null && b != null && a.constructor === Object && b.constructor === Object) {
for (j in b) {
if (!a.hasOwnProperty(j)) a[j] = b[j];
}
} else if (!Container.properties.hasOwnProperty(key)) {
Container.properties[key] = b;
}
}
}
})();
Object.defineProperties(Container.prototype, Container.properties);
Container._init_ = function() {
delete Container._init_;
}
}).call(glass)",
"www\\js\\glass\\Expression\\_parser.js": "(function() {
var global = (function() {
return this;
})();
var Expression = this;
var values; // assigned during _init_
var _parser = this._parser = {
parse: function(input, startRule) {
var parseFunctions = {
\"conditional\": parse_conditional,
\"or\": parse_or,
\"and\": parse_and,
\"equality\": parse_equality,
\"rel\": parse_rel,
\"sum\": parse_sum,
\"product\": parse_product,
\"not\": parse_not,
\"primary\": parse_primary,
\"group\": parse_group,
\"literal\": parse_literal,
\"boolean\": parse_boolean,
\"number\": parse_number,
\"hex\": parse_hex,
\"string\": parse_string,
\"array\": parse_array,
\"values\": parse_values,
\"object\": parse_object,
\"keyvalue\": parse_keyvalue,
\"keyvalues\": parse_keyvalues,
\"ref\": parse_ref,
\"id\": parse_id,
\"property\": parse_property,
\"slashProperty\": parse_slashProperty,
\"s\": parse_s,
\"path\": parse_path,
\"root\": parse_root,
\"step\": parse_step,
\"implicitDotRoot\": parse_implicitDotRoot,
\"explicitDotRoot\": parse_explicitDotRoot,
\"dotStep\": parse_dotStep,
\"noDotStep\": parse_noDotStep
};
if (startRule !== undefined) {
if (parseFunctions[startRule] === undefined) {
throw new Error(\"Invalid rule name: \" + quote(startRule) + \".\");
}
} else {
startRule = \"conditional\";
}
var pos = 0;
var reportFailures = 0;
var rightmostFailuresPos = 0;
var rightmostFailuresExpected = [];
function padLeft(input, padding, length) {
var result = input;
var padLength = length - input.length;
for (var i = 0; i < padLength; i++) {
result = padding + result;
}
return result;
}
function escape(ch) {
var charCode = ch.charCodeAt(0);
var escapeChar;
var length;
if (charCode <= 0xFF) {
escapeChar = 'x';
length = 2;
} else {
escapeChar = 'u';
length = 4;
}
return '\\\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
}
function matchFailed(failure) {
if (pos < rightmostFailuresPos) {
return;
}
if (pos > rightmostFailuresPos) {
rightmostFailuresPos = pos;
rightmostFailuresExpected = [];
}
rightmostFailuresExpected.push(failure);
}
function parse_conditional() {
var result0, result1, result2, result3, result4, result5;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_or();
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = \"?\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"?\\\"\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = \":\";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed(\"\\\":\\\"\");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = \"?\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"?\\\"\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = \":\";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed(\"\\\":\\\"\");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, e, args) {
while (args.length > 0) {
e = expr(\"?:\", [e].concat(args.pop()));
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_or() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_and();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === \"or\") {
result2 = \"or\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"or\\\"\");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === \"or\") {
result2 = \"or\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"or\\\"\");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_and() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_equality();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 3) === \"and\") {
result2 = \"and\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"and\\\"\");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 3) === \"and\") {
result2 = \"and\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"and\\\"\");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_equality() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_rel();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === \"==\") {
result2 = \"==\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"==\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \"!=\") {
result2 = \"!=\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"!=\\\"\");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === \"==\") {
result2 = \"==\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"==\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \"!=\") {
result2 = \"!=\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"!=\\\"\");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_rel() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_sum();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === \"<=\") {
result2 = \"<=\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"<=\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \">=\") {
result2 = \">=\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\">=\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = \"<\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"<\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = \">\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\">\\\"\");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === \"<=\") {
result2 = \"<=\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"<=\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \">=\") {
result2 = \">=\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\">=\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = \"<\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"<\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = \">\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\">\\\"\");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_sum() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_product();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = \"+\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"+\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \"-\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"-\\\"\");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = \"+\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"+\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \"-\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"-\\\"\");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_product() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_not();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = \"*\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"*\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \"div\") {
result2 = \"div\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"div\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \"mod\") {
result2 = \"mod\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"mod\\\"\");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = \"*\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"*\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \"div\") {
result2 = \"div\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"div\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \"mod\") {
result2 = \"mod\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"mod\\\"\");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_not() {
var result0, result1, result2;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = [];
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = \"!\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"!\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = \"~\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"~\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = \"+\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"+\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \"-\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"-\\\"\");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
while (result1 !== null) {
result0.push(result1);
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = \"!\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"!\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = \"~\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"~\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = \"+\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"+\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \"-\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"-\\\"\");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
}
if (result0 !== null) {
result1 = parse_primary();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, ops, b) {
return unaryRight(ops, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_primary() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_group();
if (result1 === null) {
result1 = parse_literal();
if (result1 === null) {
result1 = parse_path();
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_group() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = \"(\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"(\\\"\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = \")\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\")\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_literal() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_boolean();
if (result1 === null) {
result1 = parse_number();
if (result1 === null) {
result1 = parse_string();
if (result1 === null) {
result1 = parse_array();
if (result1 === null) {
result1 = parse_object();
}
}
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_boolean() {
var result0;
var pos0;
pos0 = pos;
if (input.substr(pos, 4) === \"true\") {
result0 = \"true\";
pos += 4;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"true\\\"\");
}
}
if (result0 === null) {
if (input.substr(pos, 5) === \"false\") {
result0 = \"false\";
pos += 5;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"false\\\"\");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a == \"true\";
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_number() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\"[0-9]\");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\"[0-9]\");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
pos2 = pos;
if (input.charCodeAt(pos) === 46) {
result1 = \".\";
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\"\\\".\\\"\");
}
}
if (result1 !== null) {
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"[0-9]\");
}
}
if (result3 !== null) {
result2 = [];
while (result3 !== null) {
result2.push(result3);
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"[0-9]\");
}
}
}
} else {
result2 = null;
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos2;
}
} else {
result1 = null;
pos = pos2;
}
result1 = result1 !== null ? result1: \"\";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return parseFloat(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_hex() {
var result0;
if (/^[a-fA-F0-9]/.test(input.charAt(pos))) {
result0 = input.charAt(pos);
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"[a-fA-F0-9]\");
}
}
return result0;
}
function parse_string() {
var result0, result1, result2, result3, result4, result5, result6, result7;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 34) {
result0 = \"\\\"\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\"\\\"\");
}
}
if (result0 !== null) {
result1 = [];
if (/^[\\0-!#-\\\\^-\\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"[\\\\0-!#-\\\\\\\\^-\\\\uFFFF]\");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = \"\\\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\\\\\"\");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = \"\\\"\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\"\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = \"\\\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\\\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = \"/\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"/\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = \"b\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"b\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = \"f\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"f\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = \"n\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"n\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = \"r\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"r\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = \"t\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"t\\\"\");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = \"u\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"u\\\"\");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[\\0-!#-\\\\^-\\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"[\\\\0-!#-\\\\\\\\^-\\\\uFFFF]\");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = \"\\\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\\\\\"\");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = \"\\\"\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\"\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = \"\\\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\\\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = \"/\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"/\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = \"b\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"b\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = \"f\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"f\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = \"n\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"n\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = \"r\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"r\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = \"t\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"t\\\"\");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = \"u\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"u\\\"\");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
}
if (result1 !== null) {
if (input.charCodeAt(pos) === 34) {
result2 = \"\\\"\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\"\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return JSON.parse(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_array() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = \"[\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"[\\\"\");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = \"]\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"]\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"array\", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_values() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_conditional();
result0 = result0 !== null ? result0: \"\";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \",\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\",\\\"\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \",\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\",\\\"\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, args) {
if (first != \"\") {
args.unshift(first);
}
return args;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_object() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = \"{\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"{\\\"\");
}
}
if (result0 !== null) {
result1 = parse_keyvalues();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = \"}\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"}\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"object\", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalue() {
var result0, result1, result2, result3, result4;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_string();
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
if (input.charCodeAt(pos) === 58) {
result3 = \":\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\":\\\"\");
}
}
if (result3 !== null) {
result4 = parse_conditional();
if (result4 !== null) {
result0 = [result0, result1, result2, result3, result4];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return [a, b];
})(pos0, result0[1], result0[4]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalues() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_keyvalue();
result0 = result0 !== null ? result0: \"\";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \",\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\",\\\"\");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \",\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\",\\\"\");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, rest) {
if (first) {
rest.unshift(first);
}
return rest;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_ref() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.substr(pos, 2) === \"//\") {
result0 = \"//\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"//\\\"\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 47) {
result0 = \"/\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"/\\\"\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 36) {
result0 = \"$\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"$\\\"\");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === \"**\") {
result0 = \"**\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"**\\\"\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = \"*\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"*\\\"\");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === \"..\") {
result0 = \"..\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"..\\\"\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 46) {
result0 = \".\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\".\\\"\");
}
}
}
}
}
}
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
result1 = result1 !== null ? result1: \"\";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
e = expr(a);
if (b) {
b.args.unshift(e);
e = b;
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"ref\", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_id() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\"[a-z_]\");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\"[a-z_]\");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
result1 = [];
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"[a-z_0-9]\");
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"[a-z_0-9]\");
}
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return a.join('') + b.join('');
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_property() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = \"/\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"/\\\"\");
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = \"{\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"{\\\"\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = \"}\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"}\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"{}\", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = \"[\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"[\\\"\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = \"]\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"]\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"[]\", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_slashProperty() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_number();
if (result0 === null) {
result0 = parse_string();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"/\", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.substr(pos, 2) === \"..\") {
result0 = \"..\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"..\\\"\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = \"*\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"*\\\"\");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(a, []);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_s() {
var result0, result1;
var pos0;
reportFailures++;
pos0 = pos;
result0 = [];
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\"[ ]\");
}
}
while (result1 !== null) {
result0.push(result1);
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\"[ ]\");
}
}
}
if (result0 !== null) {
result0 = (function(offset) {
return '';
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
reportFailures--;
if (reportFailures === 0 && result0 === null) {
matchFailed(\"space\");
}
return result0;
}
function parse_path() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_root();
if (result0 !== null) {
result1 = [];
result2 = parse_step();
while (result2 !== null) {
result1.push(result2);
result2 = parse_step();
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_root() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_implicitDotRoot();
if (result0 !== null) {
result1 = parse_dotStep();
result1 = result1 !== null ? result1: \"\";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinPath(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_explicitDotRoot();
}
return result0;
}
function parse_step() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = \".\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\".\\\"\");
}
}
if (result0 !== null) {
result1 = parse_dotStep();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_noDotStep();
}
return result0;
}
function parse_implicitDotRoot() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = \"/\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"/\\\"\");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr(\"root\");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 64) {
result0 = \"@\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"@\\\"\");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr(\"this\");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = \".\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\".\\\"\");
}
}
if (result0 !== null) {
if (input.charCodeAt(pos) === 46) {
result2 = \".\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\".\\\"\");
}
}
if (result2 !== null) {
result1 = [];
while (result2 !== null) {
result1.push(result2);
if (input.charCodeAt(pos) === 46) {
result2 = \".\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\".\\\"\");
}
}
}
} else {
result1 = null;
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"ancestor\", [a.length]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_explicitDotRoot() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"ref\", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = \"*\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"*\\\"\");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr(\"values\", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_dotStep() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_string();
if (result0 === null) {
result0 = parse_number();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"get\", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = \"*\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"*\\\"\");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr(\"values\", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_noDotStep() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = \"{\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"{\\\"\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = \"}\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"}\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"eval\", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = \"[\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"[\\\"\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = \"]\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"]\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"pred\", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = \"(\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"(\\\"\");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = \")\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\")\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"call\", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function cleanupExpected(expected) {
expected.sort();
var lastExpected = null;
var cleanExpected = [];
for (var i = 0; i < expected.length; i++) {
if (expected[i] !== lastExpected) {
cleanExpected.push(expected[i]);
lastExpected = expected[i];
}
}
return cleanExpected;
}
function computeErrorPosition() {
/*
* The first idea was to use |String.split| to break the input up to the
* error position along newlines and derive the line and column from
* there. However IE's |split| implementation is so broken that it was
* enough to prevent it.
*/
var line = 1;
var column = 1;
var seenCR = false;
for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
var ch = input.charAt(i);
if (ch === \"
\") {
if (!seenCR) {
line++;
}
column = 1;
seenCR = false;
} else if (ch === \"
\" || ch === \"\\u2028\" || ch === \"\\u2029\") {
line++;
column = 1;
seenCR = true;
} else {
column++;
seenCR = false;
}
}
return {
line: line,
column: column
};
}
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e, array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++) array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
var result = parseFunctions[startRule]();
/*
* The parser is now in one of the following three states:
*
* 1. The parser successfully parsed the whole input.
*
* - |result !== null|
* - |pos === input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 2. The parser successfully parsed only a part of the input.
*
* - |result !== null|
* - |pos < input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 3. The parser did not successfully parse any part of the input.
*
* - |result === null|
* - |pos === 0|
* - |rightmostFailuresExpected| contains at least one failure
*
* All code following this comment (including called functions) must
* handle these states.
*/
if (result === null || pos !== input.length) {
var offset = Math.max(pos, rightmostFailuresPos);
var found = offset < input.length ? input.charAt(offset) : null;
var errorPosition = computeErrorPosition();
throw new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column);
}
return result;
},
toSource: function() {
return this._source;
},
SyntaxError: function(expected, found, offset, line, column) {
function buildMessage(expected, found) {
var expectedHumanized, foundHumanized;
switch (expected.length) {
case 0:
expectedHumanized = \"end of input\";
break;
case 1:
expectedHumanized = expected[0];
break;
default:
expectedHumanized = expected.slice(0, expected.length - 1).join(\", \") + \" or \" + expected[expected.length - 1];
}
foundHumanized = found ? quote(found) : \"end of input\";
return \"Expected \" + expectedHumanized + \" but \" + foundHumanized + \" found.\";
}
this.name = \"SyntaxError\";
this.expected = expected;
this.found = found;
this.message = buildMessage(expected, found);
this.offset = offset;
this.line = line;
this.column = column;
},
_source: \"(function(){
/*
* Generated by PEG.js 0.7.0.
*
* http://pegjs.majda.cz/
*/
function quote(s) {
/*
* ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a
* string literal except for the closing quote character, backslash,
* carriage return, line separator, paragraph separator, and line feed.
* Any character may appear in the form of an escape sequence.
*
* For portability, we also escape escape all control and non-ASCII
* characters. Note that \\\"\\\\0\\\" and \\\"\\\\v\\\" escape sequences are not used
* because JSHint does not like the first and IE the second.
*/
return '\\\"' + s
.replace(/\\\\\\\\/g, '\\\\\\\\\\\\\\\\') // backslash
.replace(/\\\"/g, '\\\\\\\\\\\"') // closing quote character
.replace(/\\\\x08/g, '\\\\\\\\b') // backspace
.replace(/\\\\t/g, '\\\\\\\\t') // horizontal tab
.replace(/\\
/g, '\\\\\\
') // line feed
.replace(/\\\\f/g, '\\\\\\\\f') // form feed
.replace(/\\
/g, '\\\\\\
') // carriage return
.replace(/[\\\\x00-\\\\x07\\\\x0B\\\\x0E-\\\\x1F\\\\x80-\\\\uFFFF]/g, escape)
+ '\\\"';
}
var result = {
/*
* Parses the input with a generated parser. If the parsing is successfull,
* returns a value explicitly or implicitly specified by the grammar from
* which the parser was generated (see |PEG.buildParser|). If the parsing is
* unsuccessful, throws |PEG.parser.SyntaxError| describing the error.
*/
parse: function(input, startRule) {
var parseFunctions = {
\\\"conditional\\\": parse_conditional,
\\\"or\\\": parse_or,
\\\"and\\\": parse_and,
\\\"equality\\\": parse_equality,
\\\"rel\\\": parse_rel,
\\\"sum\\\": parse_sum,
\\\"product\\\": parse_product,
\\\"not\\\": parse_not,
\\\"primary\\\": parse_primary,
\\\"group\\\": parse_group,
\\\"literal\\\": parse_literal,
\\\"boolean\\\": parse_boolean,
\\\"number\\\": parse_number,
\\\"hex\\\": parse_hex,
\\\"string\\\": parse_string,
\\\"array\\\": parse_array,
\\\"values\\\": parse_values,
\\\"object\\\": parse_object,
\\\"keyvalue\\\": parse_keyvalue,
\\\"keyvalues\\\": parse_keyvalues,
\\\"ref\\\": parse_ref,
\\\"id\\\": parse_id,
\\\"property\\\": parse_property,
\\\"slashProperty\\\": parse_slashProperty,
\\\"s\\\": parse_s,
\\\"path\\\": parse_path,
\\\"root\\\": parse_root,
\\\"step\\\": parse_step,
\\\"implicitDotRoot\\\": parse_implicitDotRoot,
\\\"explicitDotRoot\\\": parse_explicitDotRoot,
\\\"dotStep\\\": parse_dotStep,
\\\"noDotStep\\\": parse_noDotStep
};
if (startRule !== undefined) {
if (parseFunctions[startRule] === undefined) {
throw new Error(\\\"Invalid rule name: \\\" + quote(startRule) + \\\".\\\");
}
} else {
startRule = \\\"conditional\\\";
}
var pos = 0;
var reportFailures = 0;
var rightmostFailuresPos = 0;
var rightmostFailuresExpected = [];
function padLeft(input, padding, length) {
var result = input;
var padLength = length - input.length;
for (var i = 0; i < padLength; i++) {
result = padding + result;
}
return result;
}
function escape(ch) {
var charCode = ch.charCodeAt(0);
var escapeChar;
var length;
if (charCode <= 0xFF) {
escapeChar = 'x';
length = 2;
} else {
escapeChar = 'u';
length = 4;
}
return '\\\\\\\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
}
function matchFailed(failure) {
if (pos < rightmostFailuresPos) {
return;
}
if (pos > rightmostFailuresPos) {
rightmostFailuresPos = pos;
rightmostFailuresExpected = [];
}
rightmostFailuresExpected.push(failure);
}
function parse_conditional() {
var result0, result1, result2, result3, result4, result5;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_or();
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = \\\"?\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"?\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = \\\":\\\";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\":\\\\\\\"\\\");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {return [b,c];})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = \\\"?\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"?\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = \\\":\\\";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\":\\\\\\\"\\\");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {return [b,c];})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, e, args) {
while (args.length > 0) {
e = expr(\\\"?:\\\", [e].concat(args.pop()));
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_or() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_and();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === \\\"or\\\") {
result2 = \\\"or\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"or\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === \\\"or\\\") {
result2 = \\\"or\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"or\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return joinLeft(a,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_and() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_equality();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 3) === \\\"and\\\") {
result2 = \\\"and\\\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"and\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 3) === \\\"and\\\") {
result2 = \\\"and\\\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"and\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return joinLeft(a,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_equality() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_rel();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === \\\"==\\\") {
result2 = \\\"==\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"==\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \\\"!=\\\") {
result2 = \\\"!=\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"!=\\\\\\\"\\\");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === \\\"==\\\") {
result2 = \\\"==\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"==\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \\\"!=\\\") {
result2 = \\\"!=\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"!=\\\\\\\"\\\");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return joinLeft(a,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_rel() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_sum();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === \\\"<=\\\") {
result2 = \\\"<=\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"<=\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \\\">=\\\") {
result2 = \\\">=\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\">=\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = \\\"<\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"<\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = \\\">\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\">\\\\\\\"\\\");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === \\\"<=\\\") {
result2 = \\\"<=\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"<=\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \\\">=\\\") {
result2 = \\\">=\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\">=\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = \\\"<\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"<\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = \\\">\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\">\\\\\\\"\\\");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return joinLeft(a,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_sum() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_product();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = \\\"+\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"+\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \\\"-\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"-\\\\\\\"\\\");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = \\\"+\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"+\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \\\"-\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"-\\\\\\\"\\\");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return joinLeft(a,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_product() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_not();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = \\\"*\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"*\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \\\"div\\\") {
result2 = \\\"div\\\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"div\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \\\"mod\\\") {
result2 = \\\"mod\\\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"mod\\\\\\\"\\\");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = \\\"*\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"*\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \\\"div\\\") {
result2 = \\\"div\\\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"div\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \\\"mod\\\") {
result2 = \\\"mod\\\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"mod\\\\\\\"\\\");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return joinLeft(a,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_not() {
var result0, result1, result2;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = [];
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = \\\"!\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"!\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = \\\"~\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"~\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = \\\"+\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"+\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \\\"-\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"-\\\\\\\"\\\");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) { return op; })(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
while (result1 !== null) {
result0.push(result1);
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = \\\"!\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"!\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = \\\"~\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"~\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = \\\"+\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"+\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \\\"-\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"-\\\\\\\"\\\");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) { return op; })(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
}
if (result0 !== null) {
result1 = parse_primary();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, ops, b) { return unaryRight(ops,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_primary() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_group();
if (result1 === null) {
result1 = parse_literal();
if (result1 === null) {
result1 = parse_path();
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return a; })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_group() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = \\\"(\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"(\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = \\\")\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\")\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return a; })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_literal() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_boolean();
if (result1 === null) {
result1 = parse_number();
if (result1 === null) {
result1 = parse_string();
if (result1 === null) {
result1 = parse_array();
if (result1 === null) {
result1 = parse_object();
}
}
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return a; })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_boolean() {
var result0;
var pos0;
pos0 = pos;
if (input.substr(pos, 4) === \\\"true\\\") {
result0 = \\\"true\\\";
pos += 4;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"true\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.substr(pos, 5) === \\\"false\\\") {
result0 = \\\"false\\\";
pos += 5;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"false\\\\\\\"\\\");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) { return a == \\\"true\\\"; })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_number() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\\\"[0-9]\\\");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\\\"[0-9]\\\");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
pos2 = pos;
if (input.charCodeAt(pos) === 46) {
result1 = \\\".\\\";
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\".\\\\\\\"\\\");
}
}
if (result1 !== null) {
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"[0-9]\\\");
}
}
if (result3 !== null) {
result2 = [];
while (result3 !== null) {
result2.push(result3);
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"[0-9]\\\");
}
}
}
} else {
result2 = null;
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos2;
}
} else {
result1 = null;
pos = pos2;
}
result1 = result1 !== null ? result1 : \\\"\\\";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return parseFloat(toString(a)); })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_hex() {
var result0;
if (/^[a-fA-F0-9]/.test(input.charAt(pos))) {
result0 = input.charAt(pos);
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"[a-fA-F0-9]\\\");
}
}
return result0;
}
function parse_string() {
var result0, result1, result2, result3, result4, result5, result6, result7;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 34) {
result0 = \\\"\\\\\\\"\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = [];
if (/^[\\\\0-!#-\\\\\\\\^-\\\\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"[\\\\\\\\0-!#-\\\\\\\\\\\\\\\\^-\\\\\\\\uFFFF]\\\");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = \\\"\\\\\\\\\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\"\\\");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = \\\"\\\\\\\"\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = \\\"\\\\\\\\\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = \\\"/\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"/\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = \\\"b\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"b\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = \\\"f\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"f\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = \\\"n\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"n\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = \\\"r\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"r\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = \\\"t\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"t\\\\\\\"\\\");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = \\\"u\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"u\\\\\\\"\\\");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[\\\\0-!#-\\\\\\\\^-\\\\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"[\\\\\\\\0-!#-\\\\\\\\\\\\\\\\^-\\\\\\\\uFFFF]\\\");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = \\\"\\\\\\\\\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\"\\\");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = \\\"\\\\\\\"\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = \\\"\\\\\\\\\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = \\\"/\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"/\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = \\\"b\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"b\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = \\\"f\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"f\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = \\\"n\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"n\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = \\\"r\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"r\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = \\\"t\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"t\\\\\\\"\\\");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = \\\"u\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"u\\\\\\\"\\\");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
}
if (result1 !== null) {
if (input.charCodeAt(pos) === 34) {
result2 = \\\"\\\\\\\"\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return JSON.parse(toString(a)); })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_array() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = \\\"[\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"[\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = \\\"]\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"]\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"array\\\", a); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_values() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_conditional();
result0 = result0 !== null ? result0 : \\\"\\\";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \\\",\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\",\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {return b;})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \\\",\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\",\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {return b;})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, args) {
if (first != \\\"\\\") { args.unshift(first); } return args;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_object() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = \\\"{\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"{\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_keyvalues();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = \\\"}\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"}\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"object\\\", a); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalue() {
var result0, result1, result2, result3, result4;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_string();
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
if (input.charCodeAt(pos) === 58) {
result3 = \\\":\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\":\\\\\\\"\\\");
}
}
if (result3 !== null) {
result4 = parse_conditional();
if (result4 !== null) {
result0 = [result0, result1, result2, result3, result4];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return [a,b]; })(pos0, result0[1], result0[4]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalues() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_keyvalue();
result0 = result0 !== null ? result0 : \\\"\\\";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \\\",\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\",\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {return b;})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \\\",\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\",\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {return b;})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, rest) {
if (first) { rest.unshift(first); } return rest;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_ref() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.substr(pos, 2) === \\\"//\\\") {
result0 = \\\"//\\\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"//\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 47) {
result0 = \\\"/\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"/\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 36) {
result0 = \\\"$\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"$\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === \\\"**\\\") {
result0 = \\\"**\\\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"**\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = \\\"*\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"*\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === \\\"..\\\") {
result0 = \\\"..\\\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"..\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 46) {
result0 = \\\".\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\".\\\\\\\"\\\");
}
}
}
}
}
}
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
result1 = result1 !== null ? result1 : \\\"\\\";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
e = expr(a); if (b) { b.args.unshift(e); e = b; } return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"ref\\\", [a]); })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_id() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\\\"[a-z_]\\\");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\\\"[a-z_]\\\");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
result1 = [];
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"[a-z_0-9]\\\");
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"[a-z_0-9]\\\");
}
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return a.join('') + b.join(''); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_property() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = \\\"/\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"/\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return a; })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = \\\"{\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"{\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = \\\"}\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"}\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"{}\\\", [a]); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = \\\"[\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"[\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = \\\"]\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"]\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"[]\\\", [a]); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_slashProperty() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_number();
if (result0 === null) {
result0 = parse_string();
}
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"/\\\", [a]); })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.substr(pos, 2) === \\\"..\\\") {
result0 = \\\"..\\\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"..\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = \\\"*\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"*\\\\\\\"\\\");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(a, []); })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_s() {
var result0, result1;
var pos0;
reportFailures++;
pos0 = pos;
result0 = [];
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\\\"[ ]\\\");
}
}
while (result1 !== null) {
result0.push(result1);
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\\\"[ ]\\\");
}
}
}
if (result0 !== null) {
result0 = (function(offset) { return ''; })(pos0);
}
if (result0 === null) {
pos = pos0;
}
reportFailures--;
if (reportFailures === 0 && result0 === null) {
matchFailed(\\\"space\\\");
}
return result0;
}
function parse_path() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_root();
if (result0 !== null) {
result1 = [];
result2 = parse_step();
while (result2 !== null) {
result1.push(result2);
result2 = parse_step();
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_root() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_implicitDotRoot();
if (result0 !== null) {
result1 = parse_dotStep();
result1 = result1 !== null ? result1 : \\\"\\\";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return joinPath(a,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_explicitDotRoot();
}
return result0;
}
function parse_step() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = \\\".\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\".\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_dotStep();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return a; })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_noDotStep();
}
return result0;
}
function parse_implicitDotRoot() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = \\\"/\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"/\\\\\\\"\\\");
}
}
if (result0 !== null) {
result0 = (function(offset) { return expr(\\\"root\\\"); })(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 64) {
result0 = \\\"@\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"@\\\\\\\"\\\");
}
}
if (result0 !== null) {
result0 = (function(offset) { return expr(\\\"this\\\"); })(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = \\\".\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\".\\\\\\\"\\\");
}
}
if (result0 !== null) {
if (input.charCodeAt(pos) === 46) {
result2 = \\\".\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\".\\\\\\\"\\\");
}
}
if (result2 !== null) {
result1 = [];
while (result2 !== null) {
result1.push(result2);
if (input.charCodeAt(pos) === 46) {
result2 = \\\".\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\".\\\\\\\"\\\");
}
}
}
} else {
result1 = null;
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"ancestor\\\", [a.length]); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_explicitDotRoot() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"ref\\\", [a]); })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = \\\"*\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"*\\\\\\\"\\\");
}
}
if (result0 !== null) {
result0 = (function(offset) { return expr(\\\"values\\\", []); })(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_dotStep() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_string();
if (result0 === null) {
result0 = parse_number();
}
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"get\\\", [a]); })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = \\\"*\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"*\\\\\\\"\\\");
}
}
if (result0 !== null) {
result0 = (function(offset) { return expr(\\\"values\\\", []); })(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_noDotStep() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = \\\"{\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"{\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = \\\"}\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"}\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"eval\\\", [a]); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = \\\"[\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"[\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = \\\"]\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"]\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"pred\\\", [a]); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = \\\"(\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"(\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = \\\")\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\")\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"call\\\", [a]); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function cleanupExpected(expected) {
expected.sort();
var lastExpected = null;
var cleanExpected = [];
for (var i = 0; i < expected.length; i++) {
if (expected[i] !== lastExpected) {
cleanExpected.push(expected[i]);
lastExpected = expected[i];
}
}
return cleanExpected;
}
function computeErrorPosition() {
/*
* The first idea was to use |String.split| to break the input up to the
* error position along newlines and derive the line and column from
* there. However IE's |split| implementation is so broken that it was
* enough to prevent it.
*/
var line = 1;
var column = 1;
var seenCR = false;
for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
var ch = input.charAt(i);
if (ch === \\\"\\
\\\") {
if (!seenCR) { line++; }
column = 1;
seenCR = false;
} else if (ch === \\\"\\
\\\" || ch === \\\"\\\\u2028\\\" || ch === \\\"\\\\u2029\\\") {
line++;
column = 1;
seenCR = true;
} else {
column++;
seenCR = false;
}
}
return { line: line, column: column };
}
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e,array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++)
array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
var result = parseFunctions[startRule]();
/*
* The parser is now in one of the following three states:
*
* 1. The parser successfully parsed the whole input.
*
* - |result !== null|
* - |pos === input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 2. The parser successfully parsed only a part of the input.
*
* - |result !== null|
* - |pos < input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 3. The parser did not successfully parse any part of the input.
*
* - |result === null|
* - |pos === 0|
* - |rightmostFailuresExpected| contains at least one failure
*
* All code following this comment (including called functions) must
* handle these states.
*/
if (result === null || pos !== input.length) {
var offset = Math.max(pos, rightmostFailuresPos);
var found = offset < input.length ? input.charAt(offset) : null;
var errorPosition = computeErrorPosition();
throw new this.SyntaxError(
cleanupExpected(rightmostFailuresExpected),
found,
offset,
errorPosition.line,
errorPosition.column
);
}
return result;
},
/* Returns the parser source code. */
toSource: function() { return this._source; }
};
/* Thrown when a parser encounters a syntax error. */
result.SyntaxError = function(expected, found, offset, line, column) {
function buildMessage(expected, found) {
var expectedHumanized, foundHumanized;
switch (expected.length) {
case 0:
expectedHumanized = \\\"end of input\\\";
break;
case 1:
expectedHumanized = expected[0];
break;
default:
expectedHumanized = expected.slice(0, expected.length - 1).join(\\\", \\\")
+ \\\" or \\\"
+ expected[expected.length - 1];
}
foundHumanized = found ? quote(found) : \\\"end of input\\\";
return \\\"Expected \\\" + expectedHumanized + \\\" but \\\" + foundHumanized + \\\" found.\\\";
}
this.name = \\\"SyntaxError\\\";
this.expected = expected;
this.found = found;
this.message = buildMessage(expected, found);
this.offset = offset;
this.line = line;
this.column = column;
};
result.SyntaxError.prototype = Error.prototype;
return result;
})()\"
};
_parser._init_ = function() {
values = global.glass.values;
delete _parser._init_;
}
}).call(glass.Expression)",
"www\\js\\glass\\allTests.js": "(function() {
var global = (function() {
return this;
})();
var glass; // assigned during _init_
var glass_Expression; // assigned during _init_
var glass_JSONMergePatch; // assigned during _init_
var glass_JSONPointer; // assigned during _init_
var glass_Observable; // assigned during _init_
var glass_Component; // assigned during _init_
var allTests = this.allTests = function anonymous(callback) {
if (callback == null) {
callback = function(path, result) {
if (result == null) {
console.log(\"\\033[92mPass\\033[0m: \" + path + \"\");
} else {
console.log(\"\\033[91mFail\\033[0m: \" + path + \"\");
console.log(result.stack || result);
}
}
}
function singleTest(path, test) {
if (test == null) {
callback(path, \"test not found\");
return;
} else if (typeof test == 'object') {
for (var key in test) singleTest(path + '.' + key, test[key]);
return;
}
try {
callback(path, test());
} catch(e) {
callback(path, e);
}
}
singleTest(\"glass\", glass.test);
singleTest(\"glass.Expression\", glass_Expression.test);
singleTest(\"glass.JSONMergePatch\", glass_JSONMergePatch.test);
singleTest(\"glass.JSONPointer\", glass_JSONPointer.test);
singleTest(\"glass.Observable\", glass_Observable.test);
singleTest(\"glass.Component\", glass_Component.test);
};
allTests._init_ = function() {
glass = global.glass;
glass_Expression = global.glass.Expression;
glass_JSONMergePatch = global.glass.JSONMergePatch;
glass_JSONPointer = global.glass.JSONPointer;
glass_Observable = global.glass.Observable;
glass_Component = global.glass.Component;
delete allTests._init_;
}
allTests._init_();
glass._init_();
glass.Expression._init_();
glass.JSONMergePatch._init_();
glass.JSONPointer._init_();
glass.Observable._init_();
glass.Component._init_();
glass.Container._init_();
glass.Expression._parser._init_();
}).call(glass)"
}
} | {
options: {
input: {
dir: "runtime",
match: /\.(coffee|pegjs)$/
},
output: {
dir: "www/js"
},
script: {
includes: "www/includes.html",
prefix: "/js/"
},
module: {
main: "glass.js",
prefix: "./www/js/"
},
debug: "buildlog.html",
test: "glass.allTests",
addon: {
pregenerate: {
addUri: function(schema) {
var content, type, typeName, _ref2, _ref3;
_ref2 = schema.types;
for (typeName in _ref2) {
type = _ref2[typeName];
content = type.content;
if (content.extension) {
continue;
}
if ((_ref3 = content.uri) == null) {
content.uri = "global:/" + (content.path.replace(/\./g, '/'));
}
}
return schema;
}
}
},
namespace: ""
},
types: {
String: {
source: "extension: true
properties:
\tstartsWith: (s) -> @slice(0,s.length) is s
\tendsWith: (s) -> @slice(-s.length) is s
\tcontains: (s) -> @indexOf(s) >= 0
\ttoArray: () -> @split ''",
input: "runtime\\String.coffee",
content: {
extension: true,
properties: {
startsWith: {
value: function(s) {
return this.slice(0, s.length) === s;
},
name: "startsWith"
},
endsWith: {
value: function(s) {
return this.slice( - s.length) === s;
},
name: "endsWith"
},
contains: {
value: function(s) {
return this.indexOf(s) >= 0;
},
name: "contains"
},
toArray: {
value: function() {
return this.split('');
},
name: "toArray"
}
},
name: "String",
path: "String",
namespace: "",
require: {},
import: {},
implements: {
String: true
}
},
isFirst: true,
output: "www\\js\\String.js"
},
glass: {
source: "require:
\tString: true
# runtime type tests
isFunction: (object) -> object? and typeof object is 'function'
isString: (object) -> object?.constructor is String
isArray: (object) -> Array.isArray object
isBoolean: (object) -> object? and typeof object is 'boolean'
isNumber: (object) -> object? and typeof object is 'number'
isObject: (object) -> typeof object is 'object'
isPlainObject: (object) -> object?.constructor is Object
isPrototype: (object) -> object? and object is object.constructor.prototype
isDate: (object) -> object?.constructor is Date
isPrimitive: (object) -> isString(object) or isBoolean(object) or isNumber(object) or isDate(object)
isPrivate: (property) -> property?[0] is '_'
# generic utility functions
values: (object) -> (value for key, value of object)
# generic patch method, uses patch method built into object if present
patch: (target, pathAndPatch...) ->
patch = JSONMergePatch.create.apply null, pathAndPatch
if isFunction target?.patch
target.patch patch
else
glass.JSONMergePatch.apply target, patch
# testing assertions
_getStackLocationInfo: (e, depth) ->
line = e.stack?.split('
')[depth]
return null unless line?
match = /\\(([\\w\\W]*?):(\\d+):(\\d+)\\)/.exec line
return {
file: match[1]
line: parseInt match[2]
column: parseInt match[3]
}
_throwAssertionFailure: (message) ->
try
throw new Error \"Assertion failed: \" + message
catch e
info = _getStackLocationInfo e, 3
if info?
_dumpFile info.file, info.line - 2, info.line + 2, info.line
throw e
_dumpFile: (file, from=1, to, highlight) ->
fs = require 'fs'
return unless fs?
try
content = fs.readFileSync(file).toString()
catch e
content = \"Source not found: #{e}\"
console.log '------------------------------------------------'
console.log file
console.log '------------------------------------------------'
number = 1
if content?
lines = content.split /
|
/
to ?= lines.length
for line in lines
lineNumber = number++
if lineNumber >= from and lineNumber <= to
num = String lineNumber
while num.length < 3
num += ' '
if lineNumber is highlight
`console.log(\"\\033[91m\" + num + \": \" + line + \"\\033[0m\");`
else
`console.log(num + \": \" + line);`
console.log '------------------------------------------------'
assert: (a) ->
_throwAssertionFailure JSON.stringify(a) unless a
assertTrue: (a) ->
_throwAssertionFailure JSON.stringify(a) + \" != true\" unless a is true
assertEquals: (a, b) ->
if JSON.stringify(a) isnt JSON.stringify(b)
_throwAssertionFailure JSON.stringify(a) + ' != ' + JSON.stringify(b)
# gets a unique string identifier for any object
getId:
do: ->
counter = 0
(a) ->
if a is null
return '__null__'
if a is undefined
return '__undefined__'
if typeof a is 'object' or typeof a is 'function'
return a.id ?= '__' + (counter++) + '__'
# 12 == \"12\" under this technique
return a.toString()
getType: (path) ->
array = if isArray path then path else path.split '.'
value = global
for step in path when value?
value = value[step]
throw new Error \"Type not found: #{path}\" unless isFunction value
value
test:
values: ->
assertEquals values({a:1,b:3,c:2}), [1,3,2]
patch: ->
x = {a:{foo:1,bar:3},b:2}
patch x, 'a', 'foo', 5
assertEquals x.a.foo, 5
",
input: "runtime\\glass.coffee",
content: {
require: {
String: "String"
},
isFunction: function(object) {
return (object != null) && typeof object === 'function';
},
isString: function(object) {
return (object != null ? object.constructor: void 0) === String;
},
isArray: function(object) {
return Array.isArray(object);
},
isBoolean: function(object) {
return (object != null) && typeof object === 'boolean';
},
isNumber: function(object) {
return (object != null) && typeof object === 'number';
},
isObject: function(object) {
return typeof object === 'object';
},
isPlainObject: function(object) {
return (object != null ? object.constructor: void 0) === Object;
},
isPrototype: function(object) {
return (object != null) && object === object.constructor.prototype;
},
isDate: function(object) {
return (object != null ? object.constructor: void 0) === Date;
},
isPrimitive: function(object) {
return isString(object) || isBoolean(object) || isNumber(object) || isDate(object);
},
isPrivate: function(property) {
return (property != null ? property[0] : void 0) === '_';
},
values: function(object) {
var key, value, _results;
_results = [];
for (key in object) {
value = object[key];
_results.push(value);
}
return _results;
},
patch: function() {
var patch, pathAndPatch, target;
target = arguments[0],
pathAndPatch = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
patch = JSONMergePatch.create.apply(null, pathAndPatch);
if (isFunction(target != null ? target.patch: void 0)) {
return target.patch(patch);
} else {
return glass.JSONMergePatch.apply(target, patch);
}
},
assert: function(a) {
if (!a) {
return _throwAssertionFailure(JSON.stringify(a));
}
},
assertTrue: function(a) {
if (a !== true) {
return _throwAssertionFailure(JSON.stringify(a) + " != true");
}
},
assertEquals: function(a, b) {
if (JSON.stringify(a) !== JSON.stringify(b)) {
return _throwAssertionFailure(JSON.stringify(a) + ' != ' + JSON.stringify(b));
}
},
getId: {
do: function() {
var counter;
counter = 0;
return function(a) {
var _ref;
if (a === null) {
return '__null__';
}
if (a === void 0) {
return '__undefined__';
}
if (typeof a === 'object' || typeof a === 'function') {
return (_ref = a.id) != null ? _ref: a.id = '__' + (counter++) + '__';
}
return a.toString();
};
}
},
getType: function(path) {
var array, step, value, _i, _len;
array = isArray(path) ? path: path.split('.');
value = global;
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
if (!isFunction(value)) {
throw new Error("Type not found: " + path);
}
return value;
},
test: {
values: function() {
return assertEquals(values({
a: 1,
b: 3,
c: 2
}), [1, 3, 2]);
},
patch: function() {
var x;
x = {
a: {
foo: 1,
bar: 3
},
b: 2
};
patch(x, 'a', 'foo', 5);
return assertEquals(x.a.foo, 5);
}
},
name: "glass",
path: "glass",
namespace: "",
import: {
"glass.JSONMergePatch": "JSONMergePatch",
"glass.isFunction": "isFunction",
"glass.isString": "isString",
"glass.isArray": "isArray",
"glass.isBoolean": "isBoolean",
"glass.isNumber": "isNumber",
"glass.isDate": "isDate",
"glass.values": "values",
"glass.patch": "patch",
"glass._getStackLocationInfo": "_getStackLocationInfo",
"glass._throwAssertionFailure": "_throwAssertionFailure",
"glass._dumpFile": "_dumpFile",
"glass.assertEquals": "assertEquals"
},
uri: "global:/glass"
},
output: "www\\js\\glass.js"
},
"glass.Expression": {
source: "constructor: (op, args) ->
@op = op
@args = args if args?
@
properties:
op:
type: 'string'
args:
type: 'array'
test: ->
return
peg = require 'pegjs'
fs = require 'fs'
parserSource = fs.readFileSync 'runtime/glass/Expression/_parser.pegjs', 'utf8'
parser = peg.buildParser parserSource
tests =
\"a.b.c\": {op:\"get\",args:[{op:\"get\",args:[{op:\"ref\",args:[\"a\"]},\"b\"]},\"c\"]}
\"a.1\": {op:\"get\",args:[{op:\"ref\",args:[\"a\"]},1]}
\"true\": true
\"false\": false
\"45.8\": 45.8
\"(45.8)\": 45.8
\"((45.8))\": 45.8
\"alpha\": {op:\"ref\",args:[\"alpha\"]}
\"35 + true * 2\": {op:\"+\", args:[35, {op:\"*\", args:[true,2]}]}
\" 5 * ( 2 + 2 ) \": {op:\"*\", args:[5, {op:\"+\", args:[2,2]}]}
\" ! ! true\": {op:\"!\",args:[{op:\"!\",args:[true]}]}
\"5 + -x\": {op:\"+\",args:[5,{op:\"-\",args:[{op:\"ref\",args:[\"x\"]}]}]}
\"true == 5 >= 2\": {op:\"==\",args:[true,{op:\">=\",args:[5,2]}]}
\"1 or 2 and 3\": {op:\"or\",args:[1,{op:\"and\",args:[2,3]}]}
\"1 ? 2 : 3\": {op:\"?:\",args:[1,2,3]}
\"1 ? 2 : 3 ? 4 : 5\" : {op:\"?:\",args:[1,2,{op:\"?:\",args:[3,4,5]}]}
\"a()(1,2)\" : {op:\"call\",args:[{op:\"call\",args:[{op:\"ref\",args:[\"a\"]},[]]},[1,2]]}
\"@\" : {op:\"this\"}
\"@foo\" : {op:\"get\",args:[{op:\"this\"},\"foo\"]}
'\"hello\"': \"hello\"
'\"\\\\t\\
\\
\\\\b\\\\\\\\foo\\\\\\/\"' : \"\\t
\\b\\\\foo\\/\"
\"[]\": {op:\"array\",args:[]}
\"[1,2]\": {op:\"array\",args:[1,2]}
\"[1+2]\": {op:\"array\",args:[{op:\"+\",args:[1,2]}]}
\"{}\": {op:\"object\",args:[]}
'{\"a\":2}': {op:\"object\",args:[[\"a\",2]]}
'{\"a\":2,\"b\":1+2}': {op:\"object\",args:[[\"a\",2],[\"b\",{op:\"+\",args:[1,2]}]]}
'@\"alpha\"': {op:\"get\",args:[{op:\"this\"},\"alpha\"]}
'*': {op:\"values\",args:[]}
'*.*': {op:\"values\",args:[{op:\"values\",args:[]}]}
\"foo.*\": {op:\"values\",args:[{op:\"ref\",args:[\"foo\"]}]}
\"..\": {op:\"ancestor\",args:[1]}
\"...\": {op:\"ancestor\",args:[2]}
\"@*{1+2}\": {op:\"eval\",args:[{op:\"values\",args:[{op:\"this\"}]},{op:\"+\",args:[1,2]}]}
\"/\": {op:\"root\"}
\"/foo\": {op:\"get\",args:[{op:\"root\"},\"foo\"]}
\"/*\": {op:\"values\",args:[{op:\"root\"}]}
for text, expected of tests
result = parser.parse text
if JSON.stringify(result) is JSON.stringify(expected)
console.log 'Pass: ' + text
else
console.log text, JSON.stringify result
return
",
input: "runtime\\glass\\Expression.coffee",
content: {
constructor: function(op, args) {
this.op = op;
if (args != null) {
this.args = args;
}
return this;
},
properties: {
op: {
type: "string",
name: "op",
writable: true
},
args: {
type: "array",
name: "args",
writable: true
}
},
test: function() {
var expected, fs, parser, parserSource, peg, result, tests, text;
return;
peg = require('pegjs');
fs = require('fs');
parserSource = fs.readFileSync('runtime/glass/Expression/_parser.pegjs', 'utf8');
parser = peg.buildParser(parserSource);
tests = {
"a.b.c": {
op: "get",
args: [{
op: "get",
args: [{
op: "ref",
args: ["a"]
},
"b"]
},
"c"]
},
"a.1": {
op: "get",
args: [{
op: "ref",
args: ["a"]
},
1]
},
"true": true,
"false": false,
"45.8": 45.8,
"(45.8)": 45.8,
"((45.8))": 45.8,
"alpha": {
op: "ref",
args: ["alpha"]
},
"35 + true * 2": {
op: "+",
args: [35, {
op: "*",
args: [true, 2]
}]
},
" 5 * ( 2 + 2 ) ": {
op: "*",
args: [5, {
op: "+",
args: [2, 2]
}]
},
" ! ! true": {
op: "!",
args: [{
op: "!",
args: [true]
}]
},
"5 + -x": {
op: "+",
args: [5, {
op: "-",
args: [{
op: "ref",
args: ["x"]
}]
}]
},
"true == 5 >= 2": {
op: "==",
args: [true, {
op: ">=",
args: [5, 2]
}]
},
"1 or 2 and 3": {
op: "or",
args: [1, {
op: "and",
args: [2, 3]
}]
},
"1 ? 2 : 3": {
op: "?:",
args: [1, 2, 3]
},
"1 ? 2 : 3 ? 4 : 5": {
op: "?:",
args: [1, 2, {
op: "?:",
args: [3, 4, 5]
}]
},
"a()(1,2)": {
op: "call",
args: [{
op: "call",
args: [{
op: "ref",
args: ["a"]
},
[]]
},
[1, 2]]
},
"@": {
op: "this"
},
"@foo": {
op: "get",
args: [{
op: "this"
},
"foo"]
},
'"hello"': "hello",
'"\\t
\\b\\\\foo\\\/"': "\t
\b\\foo\/",
"[]": {
op: "array",
args: []
},
"[1,2]": {
op: "array",
args: [1, 2]
},
"[1+2]": {
op: "array",
args: [{
op: "+",
args: [1, 2]
}]
},
"{}": {
op: "object",
args: []
},
'{"a":2}': {
op: "object",
args: [["a", 2]]
},
'{"a":2,"b":1+2}': {
op: "object",
args: [["a", 2], ["b", {
op: "+",
args: [1, 2]
}]]
},
'@"alpha"': {
op: "get",
args: [{
op: "this"
},
"alpha"]
},
'*': {
op: "values",
args: []
},
'*.*': {
op: "values",
args: [{
op: "values",
args: []
}]
},
"foo.*": {
op: "values",
args: [{
op: "ref",
args: ["foo"]
}]
},
"..": {
op: "ancestor",
args: [1]
},
"...": {
op: "ancestor",
args: [2]
},
"@*{1+2}": {
op: "eval",
args: [{
op: "values",
args: [{
op: "this"
}]
},
{
op: "+",
args: [1, 2]
}]
},
"/": {
op: "root"
},
"/foo": {
op: "get",
args: [{
op: "root"
},
"foo"]
},
"/*": {
op: "values",
args: [{
op: "root"
}]
}
};
for (text in tests) {
expected = tests[text];
result = parser.parse(text);
if (JSON.stringify(result) === JSON.stringify(expected)) {
console.log('Pass: ' + text);
} else {
console.log(text, JSON.stringify(result));
}
}
},
name: "Expression",
path: "glass.Expression",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.Expression._parser": "_parser",
"glass.values": "values"
},
implements: {
"glass.Expression": true
},
uri: "global:/glass/Expression"
},
output: "www\\js\\glass\\Expression.js"
},
"glass.JSONMergePatch": {
source: "
# applies a patch to the target object and returns the resulting target
apply: (target, patch) ->
if target? and target isnt patch and isPlainObject(patch) and not isPrimitive(target)
for key, value of patch
if value is undefined
delete target[key]
else
target[key] = apply target[key], patch[key]
return target
else
return patch
# (path1, path2, path3.., patch) ->
create: ->
if arguments.length is 1
return arguments[0]
result = {}
current = result
for arg, i in arguments when i + 1 < arguments.length
last = i + 2 is arguments.length
current = current[arg] = if last then arguments[arguments.length-1] else {}
result
test: ->
assertEquals {a:{b:12}}, create 'a', 'b', 12
assertEquals {a:3}, apply({a:1,b:2}, {a:3,b:undefined})
",
input: "runtime\\glass\\JSONMergePatch.coffee",
content: {
apply: function(target, patch) {
var key, value;
if ((target != null) && target !== patch && isPlainObject(patch) && !isPrimitive(target)) {
for (key in patch) {
value = patch[key];
if (value === void 0) {
delete target[key];
} else {
target[key] = apply(target[key], patch[key]);
}
}
return target;
} else {
return patch;
}
},
create: function() {
var arg, current, i, last, result, _i, _len;
if (arguments.length === 1) {
return arguments[0];
}
result = {};
current = result;
for (i = _i = 0, _len = arguments.length; _i < _len; i = ++_i) {
arg = arguments[i];
if (! (i + 1 < arguments.length)) {
continue;
}
last = i + 2 === arguments.length;
current = current[arg] = last ? arguments[arguments.length - 1] : {};
}
return result;
},
test: function() {
assertEquals({
a: {
b: 12
}
},
create('a', 'b', 12));
return assertEquals({
a: 3
},
apply({
a: 1,
b: 2
},
{
a: 3,
b: void 0
}));
},
name: "JSONMergePatch",
path: "glass.JSONMergePatch",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONMergePatch.apply": "apply",
"glass.JSONMergePatch.create": "create",
"glass.isPlainObject": "isPlainObject",
"glass.isPrimitive": "isPrimitive",
"glass.patch": "patch",
"glass.assertEquals": "assertEquals"
},
uri: "global:/glass/JSONMergePatch"
},
output: "www\\js\\glass\\JSONMergePatch.js"
},
"glass.JSONPointer": {
source: "# json pointer implementation as per
# http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-05
_decodeStep: (step) -> step.replace(/~1/g, '/').replace(/~0/g, '~')
_getLastStep: (pointer) ->
_decodeStep pointer.substring(pointer.lastIndexOf('/') + 1)
_getParent: (pointer) ->
if not pointer?.length
null
else
pointer.substring(0, pointer.lastIndexOf('/'))
toArray: (pointer) ->
for step in pointer.substring(1).split('/')
_decodeStep step
get: (doc, pointer) ->
value = doc
if pointer.length
path = toArray pointer
for step in path when value?
value = value[step]
value
set: (doc, pointer, value) ->
parentPointer = _getParent pointer
if parentPointer?
parent = get doc, parentPointer
lastStep = _getLastStep pointer
parent[lastStep] = value
value
test: ->
assertEquals _getParent(\"/a/b/c\"), \"/a/b\"
assertEquals _getParent(\"/a\"), \"\"
assertEquals _getParent(\"\"), null
assertEquals _getLastStep(\"/a/b/c\"), \"c\"
assertEquals _getLastStep(\"/a~0~1\"), \"a~/\"
assertEquals _getLastStep(\"\"), \"\"
# tests as per spec
doc = {
\"foo\": [\"bar\", \"baz\"],
\"\": 0,
\"a/b\": 1,
\"c%d\": 2,
\"e^f\": 3,
\"g|h\": 4,
\"i\\\\j\": 5,
\"k\\\"l\": 6,
\" \": 7,
\"m~n\": 8
}
assertEquals get(doc, \"\"), doc
assertEquals get(doc, \"/foo\"), [\"bar\", \"baz\"]
assertEquals get(doc, \"/foo/0\"), \"bar\"
assertEquals get(doc, \"/\"), 0
assertEquals get(doc, \"/a~1b\"), 1
assertEquals get(doc, \"/c%d\"), 2
assertEquals get(doc, \"/e^f\"), 3
assertEquals get(doc, \"/g|h\"), 4
assertEquals get(doc, \"/i\\\\j\"), 5
assertEquals get(doc, \"/k\\\"l\"), 6
assertEquals get(doc, \"/ \"), 7
assertEquals get(doc, \"/m~0n\"), 8
# now test set
assertEquals set(doc, \"/\", 10), 10
assertEquals doc[\"\"], 10
assertEquals set(doc, \"/foo/0\", 10), 10
assertEquals doc.foo[0], 10",
input: "runtime\\glass\\JSONPointer.coffee",
content: {
toArray: function(pointer) {
var step, _i, _len, _ref, _results;
_ref = pointer.substring(1).split('/');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
step = _ref[_i];
_results.push(_decodeStep(step));
}
return _results;
},
get: function(doc, pointer) {
var path, step, value, _i, _len;
value = doc;
if (pointer.length) {
path = toArray(pointer);
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
}
return value;
},
set: function(doc, pointer, value) {
var lastStep, parent, parentPointer;
parentPointer = _getParent(pointer);
if (parentPointer != null) {
parent = get(doc, parentPointer);
lastStep = _getLastStep(pointer);
parent[lastStep] = value;
}
return value;
},
test: function() {
var doc;
assertEquals(_getParent("/a/b/c"), "/a/b");
assertEquals(_getParent("/a"), "");
assertEquals(_getParent(""), null);
assertEquals(_getLastStep("/a/b/c"), "c");
assertEquals(_getLastStep("/a~0~1"), "a~/");
assertEquals(_getLastStep(""), "");
doc = {
"foo": ["bar", "baz"],
"": 0,
"a/b": 1,
"c%d": 2,
"e^f": 3,
"g|h": 4,
"i\\j": 5,
"k\"l": 6,
" ": 7,
"m~n": 8
};
assertEquals(get(doc, ""), doc);
assertEquals(get(doc, "/foo"), ["bar", "baz"]);
assertEquals(get(doc, "/foo/0"), "bar");
assertEquals(get(doc, "/"), 0);
assertEquals(get(doc, "/a~1b"), 1);
assertEquals(get(doc, "/c%d"), 2);
assertEquals(get(doc, "/e^f"), 3);
assertEquals(get(doc, "/g|h"), 4);
assertEquals(get(doc, "/i\\j"), 5);
assertEquals(get(doc, "/k\"l"), 6);
assertEquals(get(doc, "/ "), 7);
assertEquals(get(doc, "/m~0n"), 8);
assertEquals(set(doc, "/", 10), 10);
assertEquals(doc[""], 10);
assertEquals(set(doc, "/foo/0", 10), 10);
return assertEquals(doc.foo[0], 10);
},
name: "JSONPointer",
path: "glass.JSONPointer",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONPointer._decodeStep": "_decodeStep",
"glass.JSONPointer._getLastStep": "_getLastStep",
"glass.JSONPointer._getParent": "_getParent",
"glass.JSONPointer.toArray": "toArray",
"glass.JSONPointer.get": "get",
"glass.JSONPointer.set": "set",
"glass.assertEquals": "assertEquals"
},
uri: "global:/glass/JSONPointer"
},
output: "www\\js\\glass\\JSONPointer.js"
},
"glass.Observable": {
source: "properties:
is: (type) -> @constructor.implements[type.path ? type] is true
watchers:
serializable: false
watch: (property, watcher) ->
if isFunction property
watcher = property
property = ''
id = getId watcher
@patch 'watchers', property, id, watcher
# returns a function which will remove the watch
=> @patch 'watchers', property, getId(watcher), undefined
patch: (change) ->
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
try
JSONMergePatch.apply this, change
catch e
console.log e
finally
@notify change
return
notify: (change) ->
if @watchers?
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
for property, watchers of @watchers
if property.length is 0 or change.hasOwnProperty property
changeArg = if property.length is 0 then change else change[property]
for id, watcher of watchers
watcher this, changeArg
return
toJSON: ->
values =
class: @constructor.path
# serialize statically defined properties
for name, property of @constructor.properties
value = @[name]
if property.serializable isnt false and not isFunction(value)
values[name] = value
# serialize custom properties if allowed by schema
if @constructor.additionalProperties isnt false
for own name, value of @ when not isPrivate name
values[name] = value
values
toString: -> @toJSON()
test:
toJSON: ->
# I need this test later
# on a class that actually has serializable properties
a = new Observable
a.x = 12
a.y = ->
a.z = true
assertEquals a, {class:'glass.Observable', x:12,z:true}
watchAll: ->
# we should actually be able to watch ourselves get added to watchers
# this is very meta.
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch watcher
# now make sure we were called with our own watcher
assert watchArgs[0] is a
assert watchArgs[1]?.watchers?[\"\"]?
# reset watchArgs, and watch something else
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assertEquals a.a, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {a:{b:3}}
# now unwatch
unwatch()
# make sure universal watcher is now empty
assertEquals a.watchers[\"\"], {}
# now reset and do a new event, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
watchProperty: ->
# watch a property
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch \"foo\", watcher
# now make sure we were not called
assert watchArgs.length is 0
# reset watchArgs, and watch something else
a.patch \"foo\", \"b\", 3
assertEquals a.foo, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {b:3}
# now reset and do a different property, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
# now unwatch
unwatch()
# make sure we no longer see foo
watchArgs.length = 0
a.patch \"foo\", \"b\", 4
assert watchArgs.length is 0
",
input: "runtime\\glass\\Observable.coffee",
content: {
properties: {
is: {
value: function(type) {
var _ref;
return this.constructor["implements"][(_ref = type.path) != null ? _ref: type] === true;
},
name: "is"
},
watchers: {
serializable: false,
name: "watchers",
writable: true
},
watch: {
value: function(property, watcher) {
var id, _this = this;
if (isFunction(property)) {
watcher = property;
property = '';
}
id = getId(watcher);
this.patch('watchers', property, id, watcher);
return function() {
return _this.patch('watchers', property, getId(watcher), void 0);
};
},
name: "watch"
},
patch: {
value: function(change) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
try {
JSONMergePatch.apply(this, change);
} catch(e) {
console.log(e);
} finally {
this.notify(change);
}
},
name: "patch"
},
notify: {
value: function(change) {
var changeArg, id, property, watcher, watchers, _ref;
if (this.watchers != null) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
_ref = this.watchers;
for (property in _ref) {
watchers = _ref[property];
if (property.length === 0 || change.hasOwnProperty(property)) {
changeArg = property.length === 0 ? change: change[property];
for (id in watchers) {
watcher = watchers[id];
watcher(this, changeArg);
}
}
}
}
},
name: "notify"
},
toJSON: {
value: function() {
var name, property, value, values, _ref;
values = {
"class": this.constructor.path
};
_ref = this.constructor.properties;
for (name in _ref) {
property = _ref[name];
value = this[name];
if (property.serializable !== false && !isFunction(value)) {
values[name] = value;
}
}
if (this.constructor.additionalProperties !== false) {
for (name in this) {
if (!__hasProp.call(this, name)) continue;
value = this[name];
if (!isPrivate(name)) {
values[name] = value;
}
}
}
return values;
},
name: "toJSON"
},
toString: {
value: function() {
return this.toJSON();
},
name: "toString"
}
},
test: {
toJSON: function() {
var a;
a = new Observable;
a.x = 12;
a.y = function() {};
a.z = true;
return assertEquals(a, {
"class": 'glass.Observable',
x: 12,
z: true
});
},
watchAll: function() {
var a, unwatch, watchArgs, watcher, _ref, _ref1;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch(watcher);
assert(watchArgs[0] === a);
assert(((_ref = watchArgs[1]) != null ? (_ref1 = _ref.watchers) != null ? _ref1[""] : void 0 : void 0) != null);
watchArgs.length = 0;
a.patch("a", "b", 3);
assertEquals(a.a, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
a: {
b: 3
}
});
unwatch();
assertEquals(a.watchers[""], {});
watchArgs.length = 0;
a.patch("a", "b", 3);
return assert(watchArgs.length === 0);
},
watchProperty: function() {
var a, unwatch, watchArgs, watcher;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch("foo", watcher);
assert(watchArgs.length === 0);
a.patch("foo", "b", 3);
assertEquals(a.foo, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
b: 3
});
watchArgs.length = 0;
a.patch("a", "b", 3);
assert(watchArgs.length === 0);
unwatch();
watchArgs.length = 0;
a.patch("foo", "b", 4);
return assert(watchArgs.length === 0);
}
},
name: "Observable",
path: "glass.Observable",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONMergePatch": "JSONMergePatch",
"glass.isFunction": "isFunction",
"glass.isPrivate": "isPrivate",
"glass.values": "values",
"glass.patch": "patch",
"glass.assert": "assert",
"glass.assertEquals": "assertEquals",
"glass.getId": "getId"
},
implements: {
"glass.Observable": true
},
uri: "global:/glass/Observable"
},
output: "www\\js\\glass\\Observable.js"
},
"glass.Component": {
source: "extends: 'Observable'
constructor: (properties) ->
@patch properties
# now site ourselves on our parent
if @parent
id = getId @
patch @parent, id, @
@
properties:
id:
description: 'string which uniquely identifies this component within its parent'
type: 'string'
parent:
description: 'the object that contains this component'
serializable: false
type: 'object'
disposed: false
dispose: -> @patch 'disposed', true
notify: (change) ->
Observable.prototype.notify.apply this, arguments
if change?.disposed
# dispose of any disposable children
for id, child of @ when child?.parent is @
child.dispose?()
# remove self from parent
if @id and @parent
patch @parent, @id, undefined
return
test:
lifecycle: ->
parent = new Component
assert not parent.id?
assert not parent.parent?
child = new Component parent:parent
# id should be automatically assigned
assert isString child.id
assert parent is child.parent
assert parent[child.id] is child
assert parent.hasOwnProperty child.id
parent.dispose()
assert child.disposed is true
assert not parent.hasOwnProperty child.id
nonEnumerability: ->
visibleKeys = (key for key of new Component)
assertEquals visibleKeys, []",
input: "runtime\\glass\\Component.coffee",
content: {
extends: ["glass.Observable"],
constructor: function(properties) {
var id;
this.patch(properties);
if (this.parent) {
id = getId(this);
patch(this.parent, id, this);
}
return this;
},
properties: {
id: {
description: "string which uniquely identifies this component within its parent",
type: "string",
name: "id",
writable: true
},
parent: {
description: "the object that contains this component",
serializable: false,
type: "object",
name: "parent",
writable: true
},
disposed: {
value: false,
name: "disposed",
writable: true
},
dispose: {
value: function() {
return this.patch('disposed', true);
},
name: "dispose"
},
notify: {
value: function(change) {
var child, id;
Observable.prototype.notify.apply(this, arguments);
if (change != null ? change.disposed: void 0) {
for (id in this) {
child = this[id];
if ((child != null ? child.parent: void 0) === this) {
if (typeof child.dispose === "function") {
child.dispose();
}
}
}
if (this.id && this.parent) {
patch(this.parent, this.id, void 0);
}
}
},
name: "notify"
}
},
test: {
lifecycle: function() {
var child, parent;
parent = new Component;
assert(!(parent.id != null));
assert(!(parent.parent != null));
child = new Component({
parent: parent
});
assert(isString(child.id));
assert(parent === child.parent);
assert(parent[child.id] === child);
assert(parent.hasOwnProperty(child.id));
parent.dispose();
assert(child.disposed === true);
return assert(!parent.hasOwnProperty(child.id));
},
nonEnumerability: function() {
var key, visibleKeys;
visibleKeys = (function() {
var _results;
_results = [];
for (key in new Component) {
_results.push(key);
}
return _results;
})();
return assertEquals(visibleKeys, []);
}
},
name: "Component",
path: "glass.Component",
namespace: "glass",
require: {
glass: "glass",
"glass.Observable": "Observable"
},
import: {
"glass.Observable": "Observable",
"glass.isString": "isString",
"glass.patch": "patch",
"glass.assert": "assert",
"glass.assertEquals": "assertEquals",
"glass.getId": "getId"
},
implements: {
"glass.Component": true,
"glass.Observable": true
},
uri: "global:/glass/Component"
},
output: "www\\js\\glass\\Component.js"
},
"glass.Container": {
source: "extends: 'Observable'
properties:
watch: ->
unwatch: ->
",
input: "runtime\\glass\\Container.coffee",
content: {
extends: ["glass.Observable"],
properties: {
watch: {
value: function() {},
name: "watch"
},
unwatch: {
value: function() {},
name: "unwatch"
}
},
name: "Container",
path: "glass.Container",
namespace: "glass",
require: {
glass: "glass",
"glass.Observable": "Observable"
},
import: {},
implements: {
"glass.Container": true,
"glass.Observable": true
},
uri: "global:/glass/Container"
},
output: "www\\js\\glass\\Container.js"
},
"glass.Expression._parser": {
source: "{
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e,array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++)
array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
}
start = expression
expression = conditional
conditional = e:or args:(\"?\" b:expression \":\" c:expression {return [b,c];})* {
while (args.length > 0) {
e = expr(\"?:\", [e].concat(args.pop()));
}
return e;
}
or = a:and b:((\"or\") and)* { return joinLeft(a,b); }
and = a:equality b:((\"and\") equality)* { return joinLeft(a,b); }
equality = a:rel b:((\"==\" / \"!=\") rel)* { return joinLeft(a,b); }
rel = a:sum b:((\"<=\" / \">=\" / \"<\" / \">\") sum)* { return joinLeft(a,b); }
sum = a:product b:((\"+\" / \"-\") product)* { return joinLeft(a,b); }
product = a:not b:((\"*\" / \"div\" / \"mod\") not)* { return joinLeft(a,b); }
not = ops:(s op:(\"!\" / \"~\" / \"+\" / \"-\") { return op; })* b:primary { return unaryRight(ops,b); }
primary = s a:(group / literal / path) s { return a; }
group = \"(\" a:expression \")\" { return a; }
literal = s a:(boolean / number / string / array / object) s { return a; }
boolean = a:(\"true\" / \"false\") { return a == \"true\"; }
number = a:([0-9]+ (\".\" [0-9]+)?) { return parseFloat(toString(a)); }
hex = [a-fA-F0-9]
// as per JSON http://www.json.org
string = a:( '\"' (
[\\u0000-\\u0021\\u0023-\\u005c\\u005e-\\uffff] // all unicode chars except \\ and \"
/ (\"\\\\\" (\"\\\"\" / \"\\\\\" / \"\\/\" / \"b\" / \"f\" / \"n\" / \"r\" / \"t\" / (\"u\" hex hex hex hex)))
)* '\"' )
{ return JSON.parse(toString(a)); }
array = \"[\" a:values \"]\" { return expr(\"array\", a); }
values = first:expression? args:(\",\" b:expression {return b;})* {
if (first != \"\") { args.unshift(first); } return args;
}
object = \"{\" a:keyvalues \"}\" { return expr(\"object\", a); }
keyvalue = s a:string s \":\" b:expression { return [a,b]; }
keyvalues = first:keyvalue? rest:(\",\" b:keyvalue {return b;})* {
if (first) { rest.unshift(first); } return rest;
}
ref = a:(\"//\" / \"/\" / \"$\" / \"**\" / \"*\" / \"..\" / \".\") b:slashProperty? {
e = expr(a); if (b) { b.args.unshift(e); e = b; } return e;
}
/ a:id { return expr(\"ref\", [a]); }
id = a:[a-z_]+ b:[a-z_0-9]* { return a.join('') + b.join(''); }
property = \"/\" a:slashProperty { return a; }
/ \"{\" a:expression \"}\" { return expr(\"{}\", [a]); } // locally scoped expression
/ \"[\" a:expression \"]\" { return expr(\"[]\", [a]); } // predicate
slashProperty = a:(id/number/string) { return expr(\"/\", [a]); }
/ a:(\"..\" / \"*\") { return expr(a, []); }
s \"space\" = [ ]* { return ''; }
path = a:root b:step* {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
}
root = a:implicitDotRoot b:dotStep? { return joinPath(a,b); }
/ explicitDotRoot
step = \".\" a:dotStep { return a; }
/ noDotStep
implicitDotRoot = \"/\" { return expr(\"root\"); }
/ \"@\" { return expr(\"this\"); }
/ \".\" a:\".\"+ { return expr(\"ancestor\", [a.length]); }
explicitDotRoot = a:id { return expr(\"ref\", [a]); }
/ \"*\" { return expr(\"values\", []); }
dotStep = a:(id / string / number) { return expr(\"get\", [a]); }
/ \"*\" { return expr(\"values\", []); }
noDotStep = \"{\" a:expression \"}\" { return expr(\"eval\", [a]); }
/ \"[\" a:expression \"]\" { return expr(\"pred\", [a]); }
/ \"(\" a:values \")\" { return expr(\"call\", [a]); }
",
input: "runtime\\glass\\Expression\\_parser.pegjs",
content: {
value: {
parse: function(input, startRule) {
var parseFunctions = {
"conditional": parse_conditional,
"or": parse_or,
"and": parse_and,
"equality": parse_equality,
"rel": parse_rel,
"sum": parse_sum,
"product": parse_product,
"not": parse_not,
"primary": parse_primary,
"group": parse_group,
"literal": parse_literal,
"boolean": parse_boolean,
"number": parse_number,
"hex": parse_hex,
"string": parse_string,
"array": parse_array,
"values": parse_values,
"object": parse_object,
"keyvalue": parse_keyvalue,
"keyvalues": parse_keyvalues,
"ref": parse_ref,
"id": parse_id,
"property": parse_property,
"slashProperty": parse_slashProperty,
"s": parse_s,
"path": parse_path,
"root": parse_root,
"step": parse_step,
"implicitDotRoot": parse_implicitDotRoot,
"explicitDotRoot": parse_explicitDotRoot,
"dotStep": parse_dotStep,
"noDotStep": parse_noDotStep
};
if (startRule !== undefined) {
if (parseFunctions[startRule] === undefined) {
throw new Error("Invalid rule name: " + quote(startRule) + ".");
}
} else {
startRule = "conditional";
}
var pos = 0;
var reportFailures = 0;
var rightmostFailuresPos = 0;
var rightmostFailuresExpected = [];
function padLeft(input, padding, length) {
var result = input;
var padLength = length - input.length;
for (var i = 0; i < padLength; i++) {
result = padding + result;
}
return result;
}
function escape(ch) {
var charCode = ch.charCodeAt(0);
var escapeChar;
var length;
if (charCode <= 0xFF) {
escapeChar = 'x';
length = 2;
} else {
escapeChar = 'u';
length = 4;
}
return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
}
function matchFailed(failure) {
if (pos < rightmostFailuresPos) {
return;
}
if (pos > rightmostFailuresPos) {
rightmostFailuresPos = pos;
rightmostFailuresExpected = [];
}
rightmostFailuresExpected.push(failure);
}
function parse_conditional() {
var result0, result1, result2, result3, result4, result5;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_or();
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, e, args) {
while (args.length > 0) {
e = expr("?:", [e].concat(args.pop()));
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_or() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_and();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_and() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_equality();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_equality() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_rel();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_rel() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_sum();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_sum() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_product();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_product() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_not();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_not() {
var result0, result1, result2;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = [];
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
while (result1 !== null) {
result0.push(result1);
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
}
if (result0 !== null) {
result1 = parse_primary();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, ops, b) {
return unaryRight(ops, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_primary() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_group();
if (result1 === null) {
result1 = parse_literal();
if (result1 === null) {
result1 = parse_path();
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_group() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_literal() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_boolean();
if (result1 === null) {
result1 = parse_number();
if (result1 === null) {
result1 = parse_string();
if (result1 === null) {
result1 = parse_array();
if (result1 === null) {
result1 = parse_object();
}
}
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_boolean() {
var result0;
var pos0;
pos0 = pos;
if (input.substr(pos, 4) === "true") {
result0 = "true";
pos += 4;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"true\"");
}
}
if (result0 === null) {
if (input.substr(pos, 5) === "false") {
result0 = "false";
pos += 5;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"false\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a == "true";
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_number() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
pos2 = pos;
if (input.charCodeAt(pos) === 46) {
result1 = ".";
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result1 !== null) {
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result3 !== null) {
result2 = [];
while (result3 !== null) {
result2.push(result3);
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result2 = null;
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos2;
}
} else {
result1 = null;
pos = pos2;
}
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return parseFloat(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_hex() {
var result0;
if (/^[a-fA-F0-9]/.test(input.charAt(pos))) {
result0 = input.charAt(pos);
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("[a-fA-F0-9]");
}
}
return result0;
}
function parse_string() {
var result0, result1, result2, result3, result4, result5, result6, result7;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 34) {
result0 = "\"";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result0 !== null) {
result1 = [];
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
}
if (result1 !== null) {
if (input.charCodeAt(pos) === 34) {
result2 = "\"";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return JSON.parse(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_array() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("array", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_values() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_conditional();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, args) {
if (first != "") {
args.unshift(first);
}
return args;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_object() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_keyvalues();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("object", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalue() {
var result0, result1, result2, result3, result4;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_string();
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
if (input.charCodeAt(pos) === 58) {
result3 = ":";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result3 !== null) {
result4 = parse_conditional();
if (result4 !== null) {
result0 = [result0, result1, result2, result3, result4];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return [a, b];
})(pos0, result0[1], result0[4]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalues() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_keyvalue();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, rest) {
if (first) {
rest.unshift(first);
}
return rest;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_ref() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.substr(pos, 2) === "//") {
result0 = "//";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"//\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 36) {
result0 = "$";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"$\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "**") {
result0 = "**";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"**\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
}
}
}
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
e = expr(a);
if (b) {
b.args.unshift(e);
e = b;
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_id() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
result1 = [];
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return a.join('') + b.join('');
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_property() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("{}", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("[]", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_slashProperty() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_number();
if (result0 === null) {
result0 = parse_string();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("/", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(a, []);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_s() {
var result0, result1;
var pos0;
reportFailures++;
pos0 = pos;
result0 = [];
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
while (result1 !== null) {
result0.push(result1);
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
}
if (result0 !== null) {
result0 = (function(offset) {
return '';
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
reportFailures--;
if (reportFailures === 0 && result0 === null) {
matchFailed("space");
}
return result0;
}
function parse_path() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_root();
if (result0 !== null) {
result1 = [];
result2 = parse_step();
while (result2 !== null) {
result1.push(result2);
result2 = parse_step();
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_root() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_implicitDotRoot();
if (result0 !== null) {
result1 = parse_dotStep();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinPath(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_explicitDotRoot();
}
return result0;
}
function parse_step() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
result1 = parse_dotStep();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_noDotStep();
}
return result0;
}
function parse_implicitDotRoot() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("root");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 64) {
result0 = "@";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"@\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("this");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result2 !== null) {
result1 = [];
while (result2 !== null) {
result1.push(result2);
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
} else {
result1 = null;
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ancestor", [a.length]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_explicitDotRoot() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_dotStep() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_string();
if (result0 === null) {
result0 = parse_number();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("get", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_noDotStep() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("eval", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("pred", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("call", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function cleanupExpected(expected) {
expected.sort();
var lastExpected = null;
var cleanExpected = [];
for (var i = 0; i < expected.length; i++) {
if (expected[i] !== lastExpected) {
cleanExpected.push(expected[i]);
lastExpected = expected[i];
}
}
return cleanExpected;
}
function computeErrorPosition() {
/*
* The first idea was to use |String.split| to break the input up to the
* error position along newlines and derive the line and column from
* there. However IE's |split| implementation is so broken that it was
* enough to prevent it.
*/
var line = 1;
var column = 1;
var seenCR = false;
for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
var ch = input.charAt(i);
if (ch === "
") {
if (!seenCR) {
line++;
}
column = 1;
seenCR = false;
} else if (ch === "
" || ch === "\u2028" || ch === "\u2029") {
line++;
column = 1;
seenCR = true;
} else {
column++;
seenCR = false;
}
}
return {
line: line,
column: column
};
}
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e, array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++) array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
var result = parseFunctions[startRule]();
/*
* The parser is now in one of the following three states:
*
* 1. The parser successfully parsed the whole input.
*
* - |result !== null|
* - |pos === input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 2. The parser successfully parsed only a part of the input.
*
* - |result !== null|
* - |pos < input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 3. The parser did not successfully parse any part of the input.
*
* - |result === null|
* - |pos === 0|
* - |rightmostFailuresExpected| contains at least one failure
*
* All code following this comment (including called functions) must
* handle these states.
*/
if (result === null || pos !== input.length) {
var offset = Math.max(pos, rightmostFailuresPos);
var found = offset < input.length ? input.charAt(offset) : null;
var errorPosition = computeErrorPosition();
throw new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column);
}
return result;
},
toSource: function() {
return this._source;
},
SyntaxError: function(expected, found, offset, line, column) {
function buildMessage(expected, found) {
var expectedHumanized, foundHumanized;
switch (expected.length) {
case 0:
expectedHumanized = "end of input";
break;
case 1:
expectedHumanized = expected[0];
break;
default:
expectedHumanized = expected.slice(0, expected.length - 1).join(", ") + " or " + expected[expected.length - 1];
}
foundHumanized = found ? quote(found) : "end of input";
return "Expected " + expectedHumanized + " but " + foundHumanized + " found.";
}
this.name = "SyntaxError";
this.expected = expected;
this.found = found;
this.message = buildMessage(expected, found);
this.offset = offset;
this.line = line;
this.column = column;
}
},
name: "_parser",
path: "glass.Expression._parser",
namespace: "glass.Expression",
require: {
"glass.Expression": "Expression"
},
import: {
"glass.values": "values"
},
uri: "global:/glass/Expression/_parser"
},
output: "www\\js\\glass\\Expression\\_parser.js"
},
"glass.allTests": {
content: {
path: "glass.allTests",
name: "allTests",
namespace: "glass",
import: {
glass: "glass",
"glass.Expression": "glass_Expression",
"glass.JSONMergePatch": "glass_JSONMergePatch",
"glass.JSONPointer": "glass_JSONPointer",
"glass.Observable": "glass_Observable",
"glass.Component": "glass_Component"
},
value: function anonymous(callback) {
if (callback == null) {
callback = function(path, result) {
if (result == null) {
console.log("\033[92mPass\033[0m: " + path + "");
} else {
console.log("\033[91mFail\033[0m: " + path + "");
console.log(result.stack || result);
}
}
}
function singleTest(path, test) {
if (test == null) {
callback(path, "test not found");
return;
} else if (typeof test == 'object') {
for (var key in test) singleTest(path + '.' + key, test[key]);
return;
}
try {
callback(path, test());
} catch(e) {
callback(path, e);
}
}
singleTest("glass", glass.test);
singleTest("glass.Expression", glass_Expression.test);
singleTest("glass.JSONMergePatch", glass_JSONMergePatch.test);
singleTest("glass.JSONPointer", glass_JSONPointer.test);
singleTest("glass.Observable", glass_Observable.test);
singleTest("glass.Component", glass_Component.test);
}
},
isLast: true,
output: "www\\js\\glass\\allTests.js"
}
},
output: {
"www\\js\\String.js": "(function() {
var global = (function() {
return this;
})();
if (String.prototype.startsWith == null) {
Object.defineProperty(String.prototype, \"startsWith\", {
value: function(s) {
return this.slice(0, s.length) === s;
},
name: \"startsWith\"
});
}
if (String.prototype.endsWith == null) {
Object.defineProperty(String.prototype, \"endsWith\", {
value: function(s) {
return this.slice( - s.length) === s;
},
name: \"endsWith\"
});
}
if (String.prototype.contains == null) {
Object.defineProperty(String.prototype, \"contains\", {
value: function(s) {
return this.indexOf(s) >= 0;
},
name: \"contains\"
});
}
if (String.prototype.toArray == null) {
Object.defineProperty(String.prototype, \"toArray\", {
value: function() {
return this.split('');
},
name: \"toArray\"
});
}
String._init_ = function() {
delete String._init_;
}
}).call()",
"www\\js\\glass.js": "(function() {
var global = (function() {
return this;
})();
var JSONMergePatch; // assigned during _init_
var isFunction; // assigned during _init_
var isString; // assigned during _init_
var isArray; // assigned during _init_
var isBoolean; // assigned during _init_
var isNumber; // assigned during _init_
var isDate; // assigned during _init_
var values; // assigned during _init_
var patch; // assigned during _init_
var _getStackLocationInfo; // assigned during _init_
var _throwAssertionFailure; // assigned during _init_
var _dumpFile; // assigned during _init_
var assertEquals; // assigned during _init_
var glass = this.glass = {
isFunction: function(object) {
return (object != null) && typeof object === 'function';
},
isString: function(object) {
return (object != null ? object.constructor: void 0) === String;
},
isArray: function(object) {
return Array.isArray(object);
},
isBoolean: function(object) {
return (object != null) && typeof object === 'boolean';
},
isNumber: function(object) {
return (object != null) && typeof object === 'number';
},
isObject: function(object) {
return typeof object === 'object';
},
isPlainObject: function(object) {
return (object != null ? object.constructor: void 0) === Object;
},
isPrototype: function(object) {
return (object != null) && object === object.constructor.prototype;
},
isDate: function(object) {
return (object != null ? object.constructor: void 0) === Date;
},
isPrimitive: function(object) {
return isString(object) || isBoolean(object) || isNumber(object) || isDate(object);
},
isPrivate: function(property) {
return (property != null ? property[0] : void 0) === '_';
},
values: function(object) {
var key, value, _results;
_results = [];
for (key in object) {
value = object[key];
_results.push(value);
}
return _results;
},
patch: function() {
var patch, pathAndPatch, target;
target = arguments[0],
pathAndPatch = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
patch = JSONMergePatch.create.apply(null, pathAndPatch);
if (isFunction(target != null ? target.patch: void 0)) {
return target.patch(patch);
} else {
return glass.JSONMergePatch.apply(target, patch);
}
},
_getStackLocationInfo: function(e, depth) {
var line, match, _ref;
line = (_ref = e.stack) != null ? _ref.split('
')[depth] : void 0;
if (line == null) {
return null;
}
match = /\\(([\\w\\W]*?):(\\d+):(\\d+)\\)/.exec(line);
return {
file: match[1],
line: parseInt(match[2]),
column: parseInt(match[3])
};
},
_throwAssertionFailure: function(message) {
var info;
try {
throw new Error(\"Assertion failed: \" + message);
} catch(e) {
info = _getStackLocationInfo(e, 3);
if (info != null) {
_dumpFile(info.file, info.line - 2, info.line + 2, info.line);
}
throw e;
}
},
_dumpFile: function(file, from, to, highlight) {
var content, fs, line, lineNumber, lines, num, number, _i, _len;
if (from == null) {
from = 1;
}
fs = require('fs');
if (fs == null) {
return;
}
try {
content = fs.readFileSync(file).toString();
} catch(e) {
content = \"Source not found: \" + e;
}
console.log('------------------------------------------------');
console.log(file);
console.log('------------------------------------------------');
number = 1;
if (content != null) {
lines = content.split(/
|
/);
if (to == null) {
to = lines.length;
}
for (_i = 0, _len = lines.length; _i < _len; _i++) {
line = lines[_i];
lineNumber = number++;
if (lineNumber >= from && lineNumber <= to) {
num = String(lineNumber);
while (num.length < 3) {
num += ' ';
}
if (lineNumber === highlight) {
console.log(\"\\033[91m\" + num + \": \" + line + \"\\033[0m\");;
} else {
console.log(num + \": \" + line);;
}
}
}
}
return console.log('------------------------------------------------');
},
assert: function(a) {
if (!a) {
return _throwAssertionFailure(JSON.stringify(a));
}
},
assertTrue: function(a) {
if (a !== true) {
return _throwAssertionFailure(JSON.stringify(a) + \" != true\");
}
},
assertEquals: function(a, b) {
if (JSON.stringify(a) !== JSON.stringify(b)) {
return _throwAssertionFailure(JSON.stringify(a) + ' != ' + JSON.stringify(b));
}
},
getId: (function() {
var counter;
counter = 0;
return function(a) {
var _ref;
if (a === null) {
return '__null__';
}
if (a === void 0) {
return '__undefined__';
}
if (typeof a === 'object' || typeof a === 'function') {
return (_ref = a.id) != null ? _ref: a.id = '__' + (counter++) + '__';
}
return a.toString();
};
})(),
getType: function(path) {
var array, step, value, _i, _len;
array = isArray(path) ? path: path.split('.');
value = global;
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
if (!isFunction(value)) {
throw new Error(\"Type not found: \" + path);
}
return value;
},
test: {
values: function() {
return assertEquals(values({
a: 1,
b: 3,
c: 2
}), [1, 3, 2]);
},
patch: function() {
var x;
x = {
a: {
foo: 1,
bar: 3
},
b: 2
};
patch(x, 'a', 'foo', 5);
return assertEquals(x.a.foo, 5);
}
},
path: \"glass\",
uri: \"global:/glass\"
};
glass._init_ = function() {
JSONMergePatch = global.glass.JSONMergePatch;
isFunction = global.glass.isFunction;
isString = global.glass.isString;
isArray = global.glass.isArray;
isBoolean = global.glass.isBoolean;
isNumber = global.glass.isNumber;
isDate = global.glass.isDate;
values = global.glass.values;
patch = global.glass.patch;
_getStackLocationInfo = global.glass._getStackLocationInfo;
_throwAssertionFailure = global.glass._throwAssertionFailure;
_dumpFile = global.glass._dumpFile;
assertEquals = global.glass.assertEquals;
delete glass._init_;
}
}).call()",
"www\\js\\glass\\Expression.js": "(function() {
var global = (function() {
return this;
})();
var glass = this;
var _parser; // assigned during _init_
var values; // assigned during _init_
var Expression = this.Expression = function Expression(op, args) {
this.op = op;
if (args != null) {
this.args = args;
}
return this;
};
Expression.properties = {
op: {
type: \"string\",
name: \"op\",
writable: true
},
args: {
type: \"array\",
name: \"args\",
writable: true
}
};
Expression.test = function() {
var expected, fs, parser, parserSource, peg, result, tests, text;
return;
peg = require('pegjs');
fs = require('fs');
parserSource = fs.readFileSync('runtime/glass/Expression/_parser.pegjs', 'utf8');
parser = peg.buildParser(parserSource);
tests = {
\"a.b.c\": {
op: \"get\",
args: [{
op: \"get\",
args: [{
op: \"ref\",
args: [\"a\"]
},
\"b\"]
},
\"c\"]
},
\"a.1\": {
op: \"get\",
args: [{
op: \"ref\",
args: [\"a\"]
},
1]
},
\"true\": true,
\"false\": false,
\"45.8\": 45.8,
\"(45.8)\": 45.8,
\"((45.8))\": 45.8,
\"alpha\": {
op: \"ref\",
args: [\"alpha\"]
},
\"35 + true * 2\": {
op: \"+\",
args: [35, {
op: \"*\",
args: [true, 2]
}]
},
\" 5 * ( 2 + 2 ) \": {
op: \"*\",
args: [5, {
op: \"+\",
args: [2, 2]
}]
},
\" ! ! true\": {
op: \"!\",
args: [{
op: \"!\",
args: [true]
}]
},
\"5 + -x\": {
op: \"+\",
args: [5, {
op: \"-\",
args: [{
op: \"ref\",
args: [\"x\"]
}]
}]
},
\"true == 5 >= 2\": {
op: \"==\",
args: [true, {
op: \">=\",
args: [5, 2]
}]
},
\"1 or 2 and 3\": {
op: \"or\",
args: [1, {
op: \"and\",
args: [2, 3]
}]
},
\"1 ? 2 : 3\": {
op: \"?:\",
args: [1, 2, 3]
},
\"1 ? 2 : 3 ? 4 : 5\": {
op: \"?:\",
args: [1, 2, {
op: \"?:\",
args: [3, 4, 5]
}]
},
\"a()(1,2)\": {
op: \"call\",
args: [{
op: \"call\",
args: [{
op: \"ref\",
args: [\"a\"]
},
[]]
},
[1, 2]]
},
\"@\": {
op: \"this\"
},
\"@foo\": {
op: \"get\",
args: [{
op: \"this\"
},
\"foo\"]
},
'\"hello\"': \"hello\",
'\"\\\\t\\
\\
\\\\b\\\\\\\\foo\\\\\\/\"': \"\\t
\\b\\\\foo\\/\",
\"[]\": {
op: \"array\",
args: []
},
\"[1,2]\": {
op: \"array\",
args: [1, 2]
},
\"[1+2]\": {
op: \"array\",
args: [{
op: \"+\",
args: [1, 2]
}]
},
\"{}\": {
op: \"object\",
args: []
},
'{\"a\":2}': {
op: \"object\",
args: [[\"a\", 2]]
},
'{\"a\":2,\"b\":1+2}': {
op: \"object\",
args: [[\"a\", 2], [\"b\", {
op: \"+\",
args: [1, 2]
}]]
},
'@\"alpha\"': {
op: \"get\",
args: [{
op: \"this\"
},
\"alpha\"]
},
'*': {
op: \"values\",
args: []
},
'*.*': {
op: \"values\",
args: [{
op: \"values\",
args: []
}]
},
\"foo.*\": {
op: \"values\",
args: [{
op: \"ref\",
args: [\"foo\"]
}]
},
\"..\": {
op: \"ancestor\",
args: [1]
},
\"...\": {
op: \"ancestor\",
args: [2]
},
\"@*{1+2}\": {
op: \"eval\",
args: [{
op: \"values\",
args: [{
op: \"this\"
}]
},
{
op: \"+\",
args: [1, 2]
}]
},
\"/\": {
op: \"root\"
},
\"/foo\": {
op: \"get\",
args: [{
op: \"root\"
},
\"foo\"]
},
\"/*\": {
op: \"values\",
args: [{
op: \"root\"
}]
}
};
for (text in tests) {
expected = tests[text];
result = parser.parse(text);
if (JSON.stringify(result) === JSON.stringify(expected)) {
console.log('Pass: ' + text);
} else {
console.log(text, JSON.stringify(result));
}
}
};
Expression.path = \"glass.Expression\";
Expression.implements = {
\"glass.Expression\": true
};
Expression.uri = \"global:/glass/Expression\";
Object.defineProperties(Expression.prototype, Expression.properties);
Expression._init_ = function() {
_parser = global.glass.Expression._parser;
values = global.glass.values;
delete Expression._init_;
}
}).call(glass)",
"www\\js\\glass\\JSONMergePatch.js": "(function() {
var global = (function() {
return this;
})();
var glass = this;
var apply; // assigned during _init_
var create; // assigned during _init_
var isPlainObject; // assigned during _init_
var isPrimitive; // assigned during _init_
var patch; // assigned during _init_
var assertEquals; // assigned during _init_
var JSONMergePatch = this.JSONMergePatch = {
apply: function(target, patch) {
var key, value;
if ((target != null) && target !== patch && isPlainObject(patch) && !isPrimitive(target)) {
for (key in patch) {
value = patch[key];
if (value === void 0) {
delete target[key];
} else {
target[key] = apply(target[key], patch[key]);
}
}
return target;
} else {
return patch;
}
},
create: function() {
var arg, current, i, last, result, _i, _len;
if (arguments.length === 1) {
return arguments[0];
}
result = {};
current = result;
for (i = _i = 0, _len = arguments.length; _i < _len; i = ++_i) {
arg = arguments[i];
if (! (i + 1 < arguments.length)) {
continue;
}
last = i + 2 === arguments.length;
current = current[arg] = last ? arguments[arguments.length - 1] : {};
}
return result;
},
test: function() {
assertEquals({
a: {
b: 12
}
},
create('a', 'b', 12));
return assertEquals({
a: 3
},
apply({
a: 1,
b: 2
},
{
a: 3,
b: void 0
}));
},
path: \"glass.JSONMergePatch\",
uri: \"global:/glass/JSONMergePatch\"
};
JSONMergePatch._init_ = function() {
apply = global.glass.JSONMergePatch.apply;
create = global.glass.JSONMergePatch.create;
isPlainObject = global.glass.isPlainObject;
isPrimitive = global.glass.isPrimitive;
patch = global.glass.patch;
assertEquals = global.glass.assertEquals;
delete JSONMergePatch._init_;
}
}).call(glass)",
"www\\js\\glass\\JSONPointer.js": "(function() {
var global = (function() {
return this;
})();
var glass = this;
var _decodeStep; // assigned during _init_
var _getLastStep; // assigned during _init_
var _getParent; // assigned during _init_
var toArray; // assigned during _init_
var get; // assigned during _init_
var set; // assigned during _init_
var assertEquals; // assigned during _init_
var JSONPointer = this.JSONPointer = {
_decodeStep: function(step) {
return step.replace(/~1/g, '/').replace(/~0/g, '~');
},
_getLastStep: function(pointer) {
return _decodeStep(pointer.substring(pointer.lastIndexOf('/') + 1));
},
_getParent: function(pointer) {
if (! (pointer != null ? pointer.length: void 0)) {
return null;
} else {
return pointer.substring(0, pointer.lastIndexOf('/'));
}
},
toArray: function(pointer) {
var step, _i, _len, _ref, _results;
_ref = pointer.substring(1).split('/');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
step = _ref[_i];
_results.push(_decodeStep(step));
}
return _results;
},
get: function(doc, pointer) {
var path, step, value, _i, _len;
value = doc;
if (pointer.length) {
path = toArray(pointer);
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
}
return value;
},
set: function(doc, pointer, value) {
var lastStep, parent, parentPointer;
parentPointer = _getParent(pointer);
if (parentPointer != null) {
parent = get(doc, parentPointer);
lastStep = _getLastStep(pointer);
parent[lastStep] = value;
}
return value;
},
test: function() {
var doc;
assertEquals(_getParent(\"/a/b/c\"), \"/a/b\");
assertEquals(_getParent(\"/a\"), \"\");
assertEquals(_getParent(\"\"), null);
assertEquals(_getLastStep(\"/a/b/c\"), \"c\");
assertEquals(_getLastStep(\"/a~0~1\"), \"a~/\");
assertEquals(_getLastStep(\"\"), \"\");
doc = {
\"foo\": [\"bar\", \"baz\"],
\"\": 0,
\"a/b\": 1,
\"c%d\": 2,
\"e^f\": 3,
\"g|h\": 4,
\"i\\\\j\": 5,
\"k\\\"l\": 6,
\" \": 7,
\"m~n\": 8
};
assertEquals(get(doc, \"\"), doc);
assertEquals(get(doc, \"/foo\"), [\"bar\", \"baz\"]);
assertEquals(get(doc, \"/foo/0\"), \"bar\");
assertEquals(get(doc, \"/\"), 0);
assertEquals(get(doc, \"/a~1b\"), 1);
assertEquals(get(doc, \"/c%d\"), 2);
assertEquals(get(doc, \"/e^f\"), 3);
assertEquals(get(doc, \"/g|h\"), 4);
assertEquals(get(doc, \"/i\\\\j\"), 5);
assertEquals(get(doc, \"/k\\\"l\"), 6);
assertEquals(get(doc, \"/ \"), 7);
assertEquals(get(doc, \"/m~0n\"), 8);
assertEquals(set(doc, \"/\", 10), 10);
assertEquals(doc[\"\"], 10);
assertEquals(set(doc, \"/foo/0\", 10), 10);
return assertEquals(doc.foo[0], 10);
},
path: \"glass.JSONPointer\",
uri: \"global:/glass/JSONPointer\"
};
JSONPointer._init_ = function() {
_decodeStep = global.glass.JSONPointer._decodeStep;
_getLastStep = global.glass.JSONPointer._getLastStep;
_getParent = global.glass.JSONPointer._getParent;
toArray = global.glass.JSONPointer.toArray;
get = global.glass.JSONPointer.get;
set = global.glass.JSONPointer.set;
assertEquals = global.glass.assertEquals;
delete JSONPointer._init_;
}
}).call(glass)",
"www\\js\\glass\\Observable.js": "(function() {
var global = (function() {
return this;
})();
var glass = this;
var JSONMergePatch; // assigned during _init_
var isFunction; // assigned during _init_
var isPrivate; // assigned during _init_
var values; // assigned during _init_
var patch; // assigned during _init_
var assert; // assigned during _init_
var assertEquals; // assigned during _init_
var getId; // assigned during _init_
var Observable = this.Observable = function Observable(properties) {
var key;
if (properties != null) {
for (key in properties) {
this[key] = properties[key];
}
}
}
Observable.properties = {
is: {
value: function(type) {
var _ref;
return this.constructor[\"implements\"][(_ref = type.path) != null ? _ref: type] === true;
},
name: \"is\"
},
watchers: {
serializable: false,
name: \"watchers\",
writable: true
},
watch: {
value: function(property, watcher) {
var id, _this = this;
if (isFunction(property)) {
watcher = property;
property = '';
}
id = getId(watcher);
this.patch('watchers', property, id, watcher);
return function() {
return _this.patch('watchers', property, getId(watcher), void 0);
};
},
name: \"watch\"
},
patch: {
value: function(change) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
try {
JSONMergePatch.apply(this, change);
} catch(e) {
console.log(e);
} finally {
this.notify(change);
}
},
name: \"patch\"
},
notify: {
value: function(change) {
var changeArg, id, property, watcher, watchers, _ref;
if (this.watchers != null) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
_ref = this.watchers;
for (property in _ref) {
watchers = _ref[property];
if (property.length === 0 || change.hasOwnProperty(property)) {
changeArg = property.length === 0 ? change: change[property];
for (id in watchers) {
watcher = watchers[id];
watcher(this, changeArg);
}
}
}
}
},
name: \"notify\"
},
toJSON: {
value: function() {
var name, property, value, values, _ref;
values = {
\"class\": this.constructor.path
};
_ref = this.constructor.properties;
for (name in _ref) {
property = _ref[name];
value = this[name];
if (property.serializable !== false && !isFunction(value)) {
values[name] = value;
}
}
if (this.constructor.additionalProperties !== false) {
for (name in this) {
if (!__hasProp.call(this, name)) continue;
value = this[name];
if (!isPrivate(name)) {
values[name] = value;
}
}
}
return values;
},
name: \"toJSON\"
},
toString: {
value: function() {
return this.toJSON();
},
name: \"toString\"
}
};
Observable.test = {
toJSON: function() {
var a;
a = new Observable;
a.x = 12;
a.y = function() {};
a.z = true;
return assertEquals(a, {
\"class\": 'glass.Observable',
x: 12,
z: true
});
},
watchAll: function() {
var a, unwatch, watchArgs, watcher, _ref, _ref1;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch(watcher);
assert(watchArgs[0] === a);
assert(((_ref = watchArgs[1]) != null ? (_ref1 = _ref.watchers) != null ? _ref1[\"\"] : void 0 : void 0) != null);
watchArgs.length = 0;
a.patch(\"a\", \"b\", 3);
assertEquals(a.a, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
a: {
b: 3
}
});
unwatch();
assertEquals(a.watchers[\"\"], {});
watchArgs.length = 0;
a.patch(\"a\", \"b\", 3);
return assert(watchArgs.length === 0);
},
watchProperty: function() {
var a, unwatch, watchArgs, watcher;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch(\"foo\", watcher);
assert(watchArgs.length === 0);
a.patch(\"foo\", \"b\", 3);
assertEquals(a.foo, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
b: 3
});
watchArgs.length = 0;
a.patch(\"a\", \"b\", 3);
assert(watchArgs.length === 0);
unwatch();
watchArgs.length = 0;
a.patch(\"foo\", \"b\", 4);
return assert(watchArgs.length === 0);
}
};
Observable.path = \"glass.Observable\";
Observable.implements = {
\"glass.Observable\": true
};
Observable.uri = \"global:/glass/Observable\";
Object.defineProperties(Observable.prototype, Observable.properties);
Observable._init_ = function() {
JSONMergePatch = global.glass.JSONMergePatch;
isFunction = global.glass.isFunction;
isPrivate = global.glass.isPrivate;
values = global.glass.values;
patch = global.glass.patch;
assert = global.glass.assert;
assertEquals = global.glass.assertEquals;
getId = global.glass.getId;
delete Observable._init_;
}
}).call(glass)",
"www\\js\\glass\\Component.js": "(function() {
var global = (function() {
return this;
})();
var glass = this;
var Observable = global.glass.Observable;
var Observable; // assigned during _init_
var isString; // assigned during _init_
var patch; // assigned during _init_
var assert; // assigned during _init_
var assertEquals; // assigned during _init_
var getId; // assigned during _init_
var Component = this.Component = function Component(properties) {
var id;
this.patch(properties);
if (this.parent) {
id = getId(this);
patch(this.parent, id, this);
}
return this;
};
Component.properties = {
id: {
description: \"string which uniquely identifies this component within its parent\",
type: \"string\",
name: \"id\",
writable: true
},
parent: {
description: \"the object that contains this component\",
serializable: false,
type: \"object\",
name: \"parent\",
writable: true
},
disposed: {
value: false,
name: \"disposed\",
writable: true
},
dispose: {
value: function() {
return this.patch('disposed', true);
},
name: \"dispose\"
},
notify: {
value: function(change) {
var child, id;
Observable.prototype.notify.apply(this, arguments);
if (change != null ? change.disposed: void 0) {
for (id in this) {
child = this[id];
if ((child != null ? child.parent: void 0) === this) {
if (typeof child.dispose === \"function\") {
child.dispose();
}
}
}
if (this.id && this.parent) {
patch(this.parent, this.id, void 0);
}
}
},
name: \"notify\"
}
};
Component.test = {
lifecycle: function() {
var child, parent;
parent = new Component;
assert(!(parent.id != null));
assert(!(parent.parent != null));
child = new Component({
parent: parent
});
assert(isString(child.id));
assert(parent === child.parent);
assert(parent[child.id] === child);
assert(parent.hasOwnProperty(child.id));
parent.dispose();
assert(child.disposed === true);
return assert(!parent.hasOwnProperty(child.id));
},
nonEnumerability: function() {
var key, visibleKeys;
visibleKeys = (function() {
var _results;
_results = [];
for (key in new Component) {
_results.push(key);
}
return _results;
})();
return assertEquals(visibleKeys, []);
}
};
Component.path = \"glass.Component\";
Component.implements = {
\"glass.Component\": true,
\"glass.Observable\": true
};
Component.uri = \"global:/glass/Component\";
(function() {
var baseTypes = [Observable];
var i, j, baseType, a, b;
for (i = 0; i < baseTypes.length; i++) {
baseType = baseTypes[i];
for (key in baseType.properties) {
a = Component.properties[key];
b = baseType.properties[key];
if (a != null && b != null && a.constructor === Object && b.constructor === Object) {
for (j in b) {
if (!a.hasOwnProperty(j)) a[j] = b[j];
}
} else if (!Component.properties.hasOwnProperty(key)) {
Component.properties[key] = b;
}
}
}
})();
Object.defineProperties(Component.prototype, Component.properties);
Component._init_ = function() {
Observable = global.glass.Observable;
isString = global.glass.isString;
patch = global.glass.patch;
assert = global.glass.assert;
assertEquals = global.glass.assertEquals;
getId = global.glass.getId;
delete Component._init_;
}
}).call(glass)",
"www\\js\\glass\\Container.js": "(function() {
var global = (function() {
return this;
})();
var glass = this;
var Observable = global.glass.Observable;
var Container = this.Container = function Container(properties) {
var key;
if (properties != null) {
for (key in properties) {
this[key] = properties[key];
}
}
}
Container.properties = {
watch: {
value: function() {},
name: \"watch\"
},
unwatch: {
value: function() {},
name: \"unwatch\"
}
};
Container.path = \"glass.Container\";
Container.implements = {
\"glass.Container\": true,
\"glass.Observable\": true
};
Container.uri = \"global:/glass/Container\";
(function() {
var baseTypes = [Observable];
var i, j, baseType, a, b;
for (i = 0; i < baseTypes.length; i++) {
baseType = baseTypes[i];
for (key in baseType.properties) {
a = Container.properties[key];
b = baseType.properties[key];
if (a != null && b != null && a.constructor === Object && b.constructor === Object) {
for (j in b) {
if (!a.hasOwnProperty(j)) a[j] = b[j];
}
} else if (!Container.properties.hasOwnProperty(key)) {
Container.properties[key] = b;
}
}
}
})();
Object.defineProperties(Container.prototype, Container.properties);
Container._init_ = function() {
delete Container._init_;
}
}).call(glass)",
"www\\js\\glass\\Expression\\_parser.js": "(function() {
var global = (function() {
return this;
})();
var Expression = this;
var values; // assigned during _init_
var _parser = this._parser = {
parse: function(input, startRule) {
var parseFunctions = {
\"conditional\": parse_conditional,
\"or\": parse_or,
\"and\": parse_and,
\"equality\": parse_equality,
\"rel\": parse_rel,
\"sum\": parse_sum,
\"product\": parse_product,
\"not\": parse_not,
\"primary\": parse_primary,
\"group\": parse_group,
\"literal\": parse_literal,
\"boolean\": parse_boolean,
\"number\": parse_number,
\"hex\": parse_hex,
\"string\": parse_string,
\"array\": parse_array,
\"values\": parse_values,
\"object\": parse_object,
\"keyvalue\": parse_keyvalue,
\"keyvalues\": parse_keyvalues,
\"ref\": parse_ref,
\"id\": parse_id,
\"property\": parse_property,
\"slashProperty\": parse_slashProperty,
\"s\": parse_s,
\"path\": parse_path,
\"root\": parse_root,
\"step\": parse_step,
\"implicitDotRoot\": parse_implicitDotRoot,
\"explicitDotRoot\": parse_explicitDotRoot,
\"dotStep\": parse_dotStep,
\"noDotStep\": parse_noDotStep
};
if (startRule !== undefined) {
if (parseFunctions[startRule] === undefined) {
throw new Error(\"Invalid rule name: \" + quote(startRule) + \".\");
}
} else {
startRule = \"conditional\";
}
var pos = 0;
var reportFailures = 0;
var rightmostFailuresPos = 0;
var rightmostFailuresExpected = [];
function padLeft(input, padding, length) {
var result = input;
var padLength = length - input.length;
for (var i = 0; i < padLength; i++) {
result = padding + result;
}
return result;
}
function escape(ch) {
var charCode = ch.charCodeAt(0);
var escapeChar;
var length;
if (charCode <= 0xFF) {
escapeChar = 'x';
length = 2;
} else {
escapeChar = 'u';
length = 4;
}
return '\\\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
}
function matchFailed(failure) {
if (pos < rightmostFailuresPos) {
return;
}
if (pos > rightmostFailuresPos) {
rightmostFailuresPos = pos;
rightmostFailuresExpected = [];
}
rightmostFailuresExpected.push(failure);
}
function parse_conditional() {
var result0, result1, result2, result3, result4, result5;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_or();
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = \"?\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"?\\\"\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = \":\";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed(\"\\\":\\\"\");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = \"?\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"?\\\"\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = \":\";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed(\"\\\":\\\"\");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, e, args) {
while (args.length > 0) {
e = expr(\"?:\", [e].concat(args.pop()));
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_or() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_and();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === \"or\") {
result2 = \"or\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"or\\\"\");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === \"or\") {
result2 = \"or\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"or\\\"\");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_and() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_equality();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 3) === \"and\") {
result2 = \"and\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"and\\\"\");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 3) === \"and\") {
result2 = \"and\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"and\\\"\");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_equality() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_rel();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === \"==\") {
result2 = \"==\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"==\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \"!=\") {
result2 = \"!=\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"!=\\\"\");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === \"==\") {
result2 = \"==\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"==\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \"!=\") {
result2 = \"!=\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"!=\\\"\");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_rel() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_sum();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === \"<=\") {
result2 = \"<=\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"<=\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \">=\") {
result2 = \">=\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\">=\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = \"<\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"<\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = \">\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\">\\\"\");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === \"<=\") {
result2 = \"<=\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"<=\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \">=\") {
result2 = \">=\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\">=\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = \"<\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"<\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = \">\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\">\\\"\");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_sum() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_product();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = \"+\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"+\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \"-\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"-\\\"\");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = \"+\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"+\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \"-\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"-\\\"\");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_product() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_not();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = \"*\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"*\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \"div\") {
result2 = \"div\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"div\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \"mod\") {
result2 = \"mod\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"mod\\\"\");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = \"*\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"*\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \"div\") {
result2 = \"div\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"div\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \"mod\") {
result2 = \"mod\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"mod\\\"\");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_not() {
var result0, result1, result2;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = [];
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = \"!\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"!\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = \"~\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"~\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = \"+\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"+\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \"-\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"-\\\"\");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
while (result1 !== null) {
result0.push(result1);
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = \"!\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"!\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = \"~\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"~\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = \"+\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"+\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \"-\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"-\\\"\");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
}
if (result0 !== null) {
result1 = parse_primary();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, ops, b) {
return unaryRight(ops, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_primary() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_group();
if (result1 === null) {
result1 = parse_literal();
if (result1 === null) {
result1 = parse_path();
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_group() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = \"(\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"(\\\"\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = \")\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\")\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_literal() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_boolean();
if (result1 === null) {
result1 = parse_number();
if (result1 === null) {
result1 = parse_string();
if (result1 === null) {
result1 = parse_array();
if (result1 === null) {
result1 = parse_object();
}
}
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_boolean() {
var result0;
var pos0;
pos0 = pos;
if (input.substr(pos, 4) === \"true\") {
result0 = \"true\";
pos += 4;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"true\\\"\");
}
}
if (result0 === null) {
if (input.substr(pos, 5) === \"false\") {
result0 = \"false\";
pos += 5;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"false\\\"\");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a == \"true\";
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_number() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\"[0-9]\");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\"[0-9]\");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
pos2 = pos;
if (input.charCodeAt(pos) === 46) {
result1 = \".\";
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\"\\\".\\\"\");
}
}
if (result1 !== null) {
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"[0-9]\");
}
}
if (result3 !== null) {
result2 = [];
while (result3 !== null) {
result2.push(result3);
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"[0-9]\");
}
}
}
} else {
result2 = null;
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos2;
}
} else {
result1 = null;
pos = pos2;
}
result1 = result1 !== null ? result1: \"\";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return parseFloat(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_hex() {
var result0;
if (/^[a-fA-F0-9]/.test(input.charAt(pos))) {
result0 = input.charAt(pos);
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"[a-fA-F0-9]\");
}
}
return result0;
}
function parse_string() {
var result0, result1, result2, result3, result4, result5, result6, result7;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 34) {
result0 = \"\\\"\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\"\\\"\");
}
}
if (result0 !== null) {
result1 = [];
if (/^[\\0-!#-\\\\^-\\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"[\\\\0-!#-\\\\\\\\^-\\\\uFFFF]\");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = \"\\\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\\\\\"\");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = \"\\\"\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\"\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = \"\\\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\\\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = \"/\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"/\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = \"b\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"b\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = \"f\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"f\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = \"n\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"n\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = \"r\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"r\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = \"t\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"t\\\"\");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = \"u\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"u\\\"\");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[\\0-!#-\\\\^-\\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"[\\\\0-!#-\\\\\\\\^-\\\\uFFFF]\");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = \"\\\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\\\\\"\");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = \"\\\"\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\"\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = \"\\\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\\\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = \"/\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"/\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = \"b\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"b\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = \"f\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"f\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = \"n\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"n\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = \"r\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"r\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = \"t\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"t\\\"\");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = \"u\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"u\\\"\");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
}
if (result1 !== null) {
if (input.charCodeAt(pos) === 34) {
result2 = \"\\\"\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\"\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return JSON.parse(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_array() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = \"[\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"[\\\"\");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = \"]\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"]\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"array\", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_values() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_conditional();
result0 = result0 !== null ? result0: \"\";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \",\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\",\\\"\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \",\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\",\\\"\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, args) {
if (first != \"\") {
args.unshift(first);
}
return args;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_object() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = \"{\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"{\\\"\");
}
}
if (result0 !== null) {
result1 = parse_keyvalues();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = \"}\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"}\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"object\", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalue() {
var result0, result1, result2, result3, result4;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_string();
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
if (input.charCodeAt(pos) === 58) {
result3 = \":\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\":\\\"\");
}
}
if (result3 !== null) {
result4 = parse_conditional();
if (result4 !== null) {
result0 = [result0, result1, result2, result3, result4];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return [a, b];
})(pos0, result0[1], result0[4]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalues() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_keyvalue();
result0 = result0 !== null ? result0: \"\";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \",\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\",\\\"\");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \",\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\",\\\"\");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, rest) {
if (first) {
rest.unshift(first);
}
return rest;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_ref() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.substr(pos, 2) === \"//\") {
result0 = \"//\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"//\\\"\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 47) {
result0 = \"/\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"/\\\"\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 36) {
result0 = \"$\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"$\\\"\");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === \"**\") {
result0 = \"**\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"**\\\"\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = \"*\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"*\\\"\");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === \"..\") {
result0 = \"..\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"..\\\"\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 46) {
result0 = \".\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\".\\\"\");
}
}
}
}
}
}
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
result1 = result1 !== null ? result1: \"\";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
e = expr(a);
if (b) {
b.args.unshift(e);
e = b;
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"ref\", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_id() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\"[a-z_]\");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\"[a-z_]\");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
result1 = [];
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"[a-z_0-9]\");
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"[a-z_0-9]\");
}
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return a.join('') + b.join('');
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_property() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = \"/\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"/\\\"\");
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = \"{\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"{\\\"\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = \"}\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"}\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"{}\", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = \"[\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"[\\\"\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = \"]\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"]\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"[]\", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_slashProperty() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_number();
if (result0 === null) {
result0 = parse_string();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"/\", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.substr(pos, 2) === \"..\") {
result0 = \"..\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"..\\\"\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = \"*\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"*\\\"\");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(a, []);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_s() {
var result0, result1;
var pos0;
reportFailures++;
pos0 = pos;
result0 = [];
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\"[ ]\");
}
}
while (result1 !== null) {
result0.push(result1);
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\"[ ]\");
}
}
}
if (result0 !== null) {
result0 = (function(offset) {
return '';
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
reportFailures--;
if (reportFailures === 0 && result0 === null) {
matchFailed(\"space\");
}
return result0;
}
function parse_path() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_root();
if (result0 !== null) {
result1 = [];
result2 = parse_step();
while (result2 !== null) {
result1.push(result2);
result2 = parse_step();
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_root() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_implicitDotRoot();
if (result0 !== null) {
result1 = parse_dotStep();
result1 = result1 !== null ? result1: \"\";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinPath(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_explicitDotRoot();
}
return result0;
}
function parse_step() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = \".\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\".\\\"\");
}
}
if (result0 !== null) {
result1 = parse_dotStep();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_noDotStep();
}
return result0;
}
function parse_implicitDotRoot() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = \"/\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"/\\\"\");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr(\"root\");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 64) {
result0 = \"@\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"@\\\"\");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr(\"this\");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = \".\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\".\\\"\");
}
}
if (result0 !== null) {
if (input.charCodeAt(pos) === 46) {
result2 = \".\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\".\\\"\");
}
}
if (result2 !== null) {
result1 = [];
while (result2 !== null) {
result1.push(result2);
if (input.charCodeAt(pos) === 46) {
result2 = \".\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\".\\\"\");
}
}
}
} else {
result1 = null;
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"ancestor\", [a.length]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_explicitDotRoot() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"ref\", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = \"*\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"*\\\"\");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr(\"values\", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_dotStep() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_string();
if (result0 === null) {
result0 = parse_number();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"get\", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = \"*\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"*\\\"\");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr(\"values\", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_noDotStep() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = \"{\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"{\\\"\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = \"}\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"}\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"eval\", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = \"[\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"[\\\"\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = \"]\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"]\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"pred\", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = \"(\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"(\\\"\");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = \")\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\")\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"call\", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function cleanupExpected(expected) {
expected.sort();
var lastExpected = null;
var cleanExpected = [];
for (var i = 0; i < expected.length; i++) {
if (expected[i] !== lastExpected) {
cleanExpected.push(expected[i]);
lastExpected = expected[i];
}
}
return cleanExpected;
}
function computeErrorPosition() {
/*
* The first idea was to use |String.split| to break the input up to the
* error position along newlines and derive the line and column from
* there. However IE's |split| implementation is so broken that it was
* enough to prevent it.
*/
var line = 1;
var column = 1;
var seenCR = false;
for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
var ch = input.charAt(i);
if (ch === \"
\") {
if (!seenCR) {
line++;
}
column = 1;
seenCR = false;
} else if (ch === \"
\" || ch === \"\\u2028\" || ch === \"\\u2029\") {
line++;
column = 1;
seenCR = true;
} else {
column++;
seenCR = false;
}
}
return {
line: line,
column: column
};
}
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e, array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++) array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
var result = parseFunctions[startRule]();
/*
* The parser is now in one of the following three states:
*
* 1. The parser successfully parsed the whole input.
*
* - |result !== null|
* - |pos === input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 2. The parser successfully parsed only a part of the input.
*
* - |result !== null|
* - |pos < input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 3. The parser did not successfully parse any part of the input.
*
* - |result === null|
* - |pos === 0|
* - |rightmostFailuresExpected| contains at least one failure
*
* All code following this comment (including called functions) must
* handle these states.
*/
if (result === null || pos !== input.length) {
var offset = Math.max(pos, rightmostFailuresPos);
var found = offset < input.length ? input.charAt(offset) : null;
var errorPosition = computeErrorPosition();
throw new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column);
}
return result;
},
toSource: function() {
return this._source;
},
SyntaxError: function(expected, found, offset, line, column) {
function buildMessage(expected, found) {
var expectedHumanized, foundHumanized;
switch (expected.length) {
case 0:
expectedHumanized = \"end of input\";
break;
case 1:
expectedHumanized = expected[0];
break;
default:
expectedHumanized = expected.slice(0, expected.length - 1).join(\", \") + \" or \" + expected[expected.length - 1];
}
foundHumanized = found ? quote(found) : \"end of input\";
return \"Expected \" + expectedHumanized + \" but \" + foundHumanized + \" found.\";
}
this.name = \"SyntaxError\";
this.expected = expected;
this.found = found;
this.message = buildMessage(expected, found);
this.offset = offset;
this.line = line;
this.column = column;
},
_source: \"(function(){
/*
* Generated by PEG.js 0.7.0.
*
* http://pegjs.majda.cz/
*/
function quote(s) {
/*
* ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a
* string literal except for the closing quote character, backslash,
* carriage return, line separator, paragraph separator, and line feed.
* Any character may appear in the form of an escape sequence.
*
* For portability, we also escape escape all control and non-ASCII
* characters. Note that \\\"\\\\0\\\" and \\\"\\\\v\\\" escape sequences are not used
* because JSHint does not like the first and IE the second.
*/
return '\\\"' + s
.replace(/\\\\\\\\/g, '\\\\\\\\\\\\\\\\') // backslash
.replace(/\\\"/g, '\\\\\\\\\\\"') // closing quote character
.replace(/\\\\x08/g, '\\\\\\\\b') // backspace
.replace(/\\\\t/g, '\\\\\\\\t') // horizontal tab
.replace(/\\
/g, '\\\\\\
') // line feed
.replace(/\\\\f/g, '\\\\\\\\f') // form feed
.replace(/\\
/g, '\\\\\\
') // carriage return
.replace(/[\\\\x00-\\\\x07\\\\x0B\\\\x0E-\\\\x1F\\\\x80-\\\\uFFFF]/g, escape)
+ '\\\"';
}
var result = {
/*
* Parses the input with a generated parser. If the parsing is successfull,
* returns a value explicitly or implicitly specified by the grammar from
* which the parser was generated (see |PEG.buildParser|). If the parsing is
* unsuccessful, throws |PEG.parser.SyntaxError| describing the error.
*/
parse: function(input, startRule) {
var parseFunctions = {
\\\"conditional\\\": parse_conditional,
\\\"or\\\": parse_or,
\\\"and\\\": parse_and,
\\\"equality\\\": parse_equality,
\\\"rel\\\": parse_rel,
\\\"sum\\\": parse_sum,
\\\"product\\\": parse_product,
\\\"not\\\": parse_not,
\\\"primary\\\": parse_primary,
\\\"group\\\": parse_group,
\\\"literal\\\": parse_literal,
\\\"boolean\\\": parse_boolean,
\\\"number\\\": parse_number,
\\\"hex\\\": parse_hex,
\\\"string\\\": parse_string,
\\\"array\\\": parse_array,
\\\"values\\\": parse_values,
\\\"object\\\": parse_object,
\\\"keyvalue\\\": parse_keyvalue,
\\\"keyvalues\\\": parse_keyvalues,
\\\"ref\\\": parse_ref,
\\\"id\\\": parse_id,
\\\"property\\\": parse_property,
\\\"slashProperty\\\": parse_slashProperty,
\\\"s\\\": parse_s,
\\\"path\\\": parse_path,
\\\"root\\\": parse_root,
\\\"step\\\": parse_step,
\\\"implicitDotRoot\\\": parse_implicitDotRoot,
\\\"explicitDotRoot\\\": parse_explicitDotRoot,
\\\"dotStep\\\": parse_dotStep,
\\\"noDotStep\\\": parse_noDotStep
};
if (startRule !== undefined) {
if (parseFunctions[startRule] === undefined) {
throw new Error(\\\"Invalid rule name: \\\" + quote(startRule) + \\\".\\\");
}
} else {
startRule = \\\"conditional\\\";
}
var pos = 0;
var reportFailures = 0;
var rightmostFailuresPos = 0;
var rightmostFailuresExpected = [];
function padLeft(input, padding, length) {
var result = input;
var padLength = length - input.length;
for (var i = 0; i < padLength; i++) {
result = padding + result;
}
return result;
}
function escape(ch) {
var charCode = ch.charCodeAt(0);
var escapeChar;
var length;
if (charCode <= 0xFF) {
escapeChar = 'x';
length = 2;
} else {
escapeChar = 'u';
length = 4;
}
return '\\\\\\\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
}
function matchFailed(failure) {
if (pos < rightmostFailuresPos) {
return;
}
if (pos > rightmostFailuresPos) {
rightmostFailuresPos = pos;
rightmostFailuresExpected = [];
}
rightmostFailuresExpected.push(failure);
}
function parse_conditional() {
var result0, result1, result2, result3, result4, result5;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_or();
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = \\\"?\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"?\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = \\\":\\\";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\":\\\\\\\"\\\");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {return [b,c];})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = \\\"?\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"?\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = \\\":\\\";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\":\\\\\\\"\\\");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {return [b,c];})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, e, args) {
while (args.length > 0) {
e = expr(\\\"?:\\\", [e].concat(args.pop()));
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_or() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_and();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === \\\"or\\\") {
result2 = \\\"or\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"or\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === \\\"or\\\") {
result2 = \\\"or\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"or\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return joinLeft(a,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_and() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_equality();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 3) === \\\"and\\\") {
result2 = \\\"and\\\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"and\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 3) === \\\"and\\\") {
result2 = \\\"and\\\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"and\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return joinLeft(a,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_equality() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_rel();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === \\\"==\\\") {
result2 = \\\"==\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"==\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \\\"!=\\\") {
result2 = \\\"!=\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"!=\\\\\\\"\\\");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === \\\"==\\\") {
result2 = \\\"==\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"==\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \\\"!=\\\") {
result2 = \\\"!=\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"!=\\\\\\\"\\\");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return joinLeft(a,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_rel() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_sum();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === \\\"<=\\\") {
result2 = \\\"<=\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"<=\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \\\">=\\\") {
result2 = \\\">=\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\">=\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = \\\"<\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"<\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = \\\">\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\">\\\\\\\"\\\");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === \\\"<=\\\") {
result2 = \\\"<=\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"<=\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \\\">=\\\") {
result2 = \\\">=\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\">=\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = \\\"<\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"<\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = \\\">\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\">\\\\\\\"\\\");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return joinLeft(a,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_sum() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_product();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = \\\"+\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"+\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \\\"-\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"-\\\\\\\"\\\");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = \\\"+\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"+\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \\\"-\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"-\\\\\\\"\\\");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return joinLeft(a,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_product() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_not();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = \\\"*\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"*\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \\\"div\\\") {
result2 = \\\"div\\\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"div\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \\\"mod\\\") {
result2 = \\\"mod\\\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"mod\\\\\\\"\\\");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = \\\"*\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"*\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \\\"div\\\") {
result2 = \\\"div\\\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"div\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \\\"mod\\\") {
result2 = \\\"mod\\\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"mod\\\\\\\"\\\");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return joinLeft(a,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_not() {
var result0, result1, result2;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = [];
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = \\\"!\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"!\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = \\\"~\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"~\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = \\\"+\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"+\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \\\"-\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"-\\\\\\\"\\\");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) { return op; })(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
while (result1 !== null) {
result0.push(result1);
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = \\\"!\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"!\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = \\\"~\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"~\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = \\\"+\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"+\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \\\"-\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"-\\\\\\\"\\\");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) { return op; })(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
}
if (result0 !== null) {
result1 = parse_primary();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, ops, b) { return unaryRight(ops,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_primary() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_group();
if (result1 === null) {
result1 = parse_literal();
if (result1 === null) {
result1 = parse_path();
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return a; })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_group() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = \\\"(\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"(\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = \\\")\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\")\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return a; })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_literal() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_boolean();
if (result1 === null) {
result1 = parse_number();
if (result1 === null) {
result1 = parse_string();
if (result1 === null) {
result1 = parse_array();
if (result1 === null) {
result1 = parse_object();
}
}
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return a; })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_boolean() {
var result0;
var pos0;
pos0 = pos;
if (input.substr(pos, 4) === \\\"true\\\") {
result0 = \\\"true\\\";
pos += 4;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"true\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.substr(pos, 5) === \\\"false\\\") {
result0 = \\\"false\\\";
pos += 5;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"false\\\\\\\"\\\");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) { return a == \\\"true\\\"; })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_number() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\\\"[0-9]\\\");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\\\"[0-9]\\\");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
pos2 = pos;
if (input.charCodeAt(pos) === 46) {
result1 = \\\".\\\";
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\".\\\\\\\"\\\");
}
}
if (result1 !== null) {
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"[0-9]\\\");
}
}
if (result3 !== null) {
result2 = [];
while (result3 !== null) {
result2.push(result3);
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"[0-9]\\\");
}
}
}
} else {
result2 = null;
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos2;
}
} else {
result1 = null;
pos = pos2;
}
result1 = result1 !== null ? result1 : \\\"\\\";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return parseFloat(toString(a)); })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_hex() {
var result0;
if (/^[a-fA-F0-9]/.test(input.charAt(pos))) {
result0 = input.charAt(pos);
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"[a-fA-F0-9]\\\");
}
}
return result0;
}
function parse_string() {
var result0, result1, result2, result3, result4, result5, result6, result7;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 34) {
result0 = \\\"\\\\\\\"\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = [];
if (/^[\\\\0-!#-\\\\\\\\^-\\\\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"[\\\\\\\\0-!#-\\\\\\\\\\\\\\\\^-\\\\\\\\uFFFF]\\\");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = \\\"\\\\\\\\\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\"\\\");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = \\\"\\\\\\\"\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = \\\"\\\\\\\\\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = \\\"/\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"/\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = \\\"b\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"b\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = \\\"f\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"f\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = \\\"n\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"n\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = \\\"r\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"r\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = \\\"t\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"t\\\\\\\"\\\");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = \\\"u\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"u\\\\\\\"\\\");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[\\\\0-!#-\\\\\\\\^-\\\\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"[\\\\\\\\0-!#-\\\\\\\\\\\\\\\\^-\\\\\\\\uFFFF]\\\");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = \\\"\\\\\\\\\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\"\\\");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = \\\"\\\\\\\"\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = \\\"\\\\\\\\\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = \\\"/\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"/\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = \\\"b\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"b\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = \\\"f\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"f\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = \\\"n\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"n\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = \\\"r\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"r\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = \\\"t\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"t\\\\\\\"\\\");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = \\\"u\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"u\\\\\\\"\\\");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
}
if (result1 !== null) {
if (input.charCodeAt(pos) === 34) {
result2 = \\\"\\\\\\\"\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return JSON.parse(toString(a)); })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_array() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = \\\"[\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"[\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = \\\"]\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"]\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"array\\\", a); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_values() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_conditional();
result0 = result0 !== null ? result0 : \\\"\\\";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \\\",\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\",\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {return b;})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \\\",\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\",\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {return b;})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, args) {
if (first != \\\"\\\") { args.unshift(first); } return args;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_object() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = \\\"{\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"{\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_keyvalues();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = \\\"}\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"}\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"object\\\", a); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalue() {
var result0, result1, result2, result3, result4;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_string();
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
if (input.charCodeAt(pos) === 58) {
result3 = \\\":\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\":\\\\\\\"\\\");
}
}
if (result3 !== null) {
result4 = parse_conditional();
if (result4 !== null) {
result0 = [result0, result1, result2, result3, result4];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return [a,b]; })(pos0, result0[1], result0[4]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalues() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_keyvalue();
result0 = result0 !== null ? result0 : \\\"\\\";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \\\",\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\",\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {return b;})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \\\",\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\",\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {return b;})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, rest) {
if (first) { rest.unshift(first); } return rest;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_ref() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.substr(pos, 2) === \\\"//\\\") {
result0 = \\\"//\\\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"//\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 47) {
result0 = \\\"/\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"/\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 36) {
result0 = \\\"$\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"$\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === \\\"**\\\") {
result0 = \\\"**\\\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"**\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = \\\"*\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"*\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === \\\"..\\\") {
result0 = \\\"..\\\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"..\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 46) {
result0 = \\\".\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\".\\\\\\\"\\\");
}
}
}
}
}
}
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
result1 = result1 !== null ? result1 : \\\"\\\";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
e = expr(a); if (b) { b.args.unshift(e); e = b; } return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"ref\\\", [a]); })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_id() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\\\"[a-z_]\\\");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\\\"[a-z_]\\\");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
result1 = [];
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"[a-z_0-9]\\\");
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"[a-z_0-9]\\\");
}
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return a.join('') + b.join(''); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_property() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = \\\"/\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"/\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return a; })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = \\\"{\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"{\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = \\\"}\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"}\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"{}\\\", [a]); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = \\\"[\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"[\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = \\\"]\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"]\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"[]\\\", [a]); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_slashProperty() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_number();
if (result0 === null) {
result0 = parse_string();
}
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"/\\\", [a]); })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.substr(pos, 2) === \\\"..\\\") {
result0 = \\\"..\\\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"..\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = \\\"*\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"*\\\\\\\"\\\");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(a, []); })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_s() {
var result0, result1;
var pos0;
reportFailures++;
pos0 = pos;
result0 = [];
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\\\"[ ]\\\");
}
}
while (result1 !== null) {
result0.push(result1);
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\\\"[ ]\\\");
}
}
}
if (result0 !== null) {
result0 = (function(offset) { return ''; })(pos0);
}
if (result0 === null) {
pos = pos0;
}
reportFailures--;
if (reportFailures === 0 && result0 === null) {
matchFailed(\\\"space\\\");
}
return result0;
}
function parse_path() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_root();
if (result0 !== null) {
result1 = [];
result2 = parse_step();
while (result2 !== null) {
result1.push(result2);
result2 = parse_step();
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_root() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_implicitDotRoot();
if (result0 !== null) {
result1 = parse_dotStep();
result1 = result1 !== null ? result1 : \\\"\\\";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return joinPath(a,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_explicitDotRoot();
}
return result0;
}
function parse_step() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = \\\".\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\".\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_dotStep();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return a; })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_noDotStep();
}
return result0;
}
function parse_implicitDotRoot() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = \\\"/\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"/\\\\\\\"\\\");
}
}
if (result0 !== null) {
result0 = (function(offset) { return expr(\\\"root\\\"); })(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 64) {
result0 = \\\"@\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"@\\\\\\\"\\\");
}
}
if (result0 !== null) {
result0 = (function(offset) { return expr(\\\"this\\\"); })(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = \\\".\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\".\\\\\\\"\\\");
}
}
if (result0 !== null) {
if (input.charCodeAt(pos) === 46) {
result2 = \\\".\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\".\\\\\\\"\\\");
}
}
if (result2 !== null) {
result1 = [];
while (result2 !== null) {
result1.push(result2);
if (input.charCodeAt(pos) === 46) {
result2 = \\\".\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\".\\\\\\\"\\\");
}
}
}
} else {
result1 = null;
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"ancestor\\\", [a.length]); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_explicitDotRoot() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"ref\\\", [a]); })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = \\\"*\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"*\\\\\\\"\\\");
}
}
if (result0 !== null) {
result0 = (function(offset) { return expr(\\\"values\\\", []); })(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_dotStep() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_string();
if (result0 === null) {
result0 = parse_number();
}
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"get\\\", [a]); })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = \\\"*\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"*\\\\\\\"\\\");
}
}
if (result0 !== null) {
result0 = (function(offset) { return expr(\\\"values\\\", []); })(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_noDotStep() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = \\\"{\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"{\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = \\\"}\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"}\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"eval\\\", [a]); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = \\\"[\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"[\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = \\\"]\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"]\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"pred\\\", [a]); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = \\\"(\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"(\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = \\\")\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\")\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"call\\\", [a]); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function cleanupExpected(expected) {
expected.sort();
var lastExpected = null;
var cleanExpected = [];
for (var i = 0; i < expected.length; i++) {
if (expected[i] !== lastExpected) {
cleanExpected.push(expected[i]);
lastExpected = expected[i];
}
}
return cleanExpected;
}
function computeErrorPosition() {
/*
* The first idea was to use |String.split| to break the input up to the
* error position along newlines and derive the line and column from
* there. However IE's |split| implementation is so broken that it was
* enough to prevent it.
*/
var line = 1;
var column = 1;
var seenCR = false;
for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
var ch = input.charAt(i);
if (ch === \\\"\\
\\\") {
if (!seenCR) { line++; }
column = 1;
seenCR = false;
} else if (ch === \\\"\\
\\\" || ch === \\\"\\\\u2028\\\" || ch === \\\"\\\\u2029\\\") {
line++;
column = 1;
seenCR = true;
} else {
column++;
seenCR = false;
}
}
return { line: line, column: column };
}
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e,array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++)
array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
var result = parseFunctions[startRule]();
/*
* The parser is now in one of the following three states:
*
* 1. The parser successfully parsed the whole input.
*
* - |result !== null|
* - |pos === input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 2. The parser successfully parsed only a part of the input.
*
* - |result !== null|
* - |pos < input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 3. The parser did not successfully parse any part of the input.
*
* - |result === null|
* - |pos === 0|
* - |rightmostFailuresExpected| contains at least one failure
*
* All code following this comment (including called functions) must
* handle these states.
*/
if (result === null || pos !== input.length) {
var offset = Math.max(pos, rightmostFailuresPos);
var found = offset < input.length ? input.charAt(offset) : null;
var errorPosition = computeErrorPosition();
throw new this.SyntaxError(
cleanupExpected(rightmostFailuresExpected),
found,
offset,
errorPosition.line,
errorPosition.column
);
}
return result;
},
/* Returns the parser source code. */
toSource: function() { return this._source; }
};
/* Thrown when a parser encounters a syntax error. */
result.SyntaxError = function(expected, found, offset, line, column) {
function buildMessage(expected, found) {
var expectedHumanized, foundHumanized;
switch (expected.length) {
case 0:
expectedHumanized = \\\"end of input\\\";
break;
case 1:
expectedHumanized = expected[0];
break;
default:
expectedHumanized = expected.slice(0, expected.length - 1).join(\\\", \\\")
+ \\\" or \\\"
+ expected[expected.length - 1];
}
foundHumanized = found ? quote(found) : \\\"end of input\\\";
return \\\"Expected \\\" + expectedHumanized + \\\" but \\\" + foundHumanized + \\\" found.\\\";
}
this.name = \\\"SyntaxError\\\";
this.expected = expected;
this.found = found;
this.message = buildMessage(expected, found);
this.offset = offset;
this.line = line;
this.column = column;
};
result.SyntaxError.prototype = Error.prototype;
return result;
})()\"
};
_parser._init_ = function() {
values = global.glass.values;
delete _parser._init_;
}
}).call(glass.Expression)",
"www\\js\\glass\\allTests.js": "(function() {
var global = (function() {
return this;
})();
var glass; // assigned during _init_
var glass_Expression; // assigned during _init_
var glass_JSONMergePatch; // assigned during _init_
var glass_JSONPointer; // assigned during _init_
var glass_Observable; // assigned during _init_
var glass_Component; // assigned during _init_
var allTests = this.allTests = function anonymous(callback) {
if (callback == null) {
callback = function(path, result) {
if (result == null) {
console.log(\"\\033[92mPass\\033[0m: \" + path + \"\");
} else {
console.log(\"\\033[91mFail\\033[0m: \" + path + \"\");
console.log(result.stack || result);
}
}
}
function singleTest(path, test) {
if (test == null) {
callback(path, \"test not found\");
return;
} else if (typeof test == 'object') {
for (var key in test) singleTest(path + '.' + key, test[key]);
return;
}
try {
callback(path, test());
} catch(e) {
callback(path, e);
}
}
singleTest(\"glass\", glass.test);
singleTest(\"glass.Expression\", glass_Expression.test);
singleTest(\"glass.JSONMergePatch\", glass_JSONMergePatch.test);
singleTest(\"glass.JSONPointer\", glass_JSONPointer.test);
singleTest(\"glass.Observable\", glass_Observable.test);
singleTest(\"glass.Component\", glass_Component.test);
};
allTests._init_ = function() {
glass = global.glass;
glass_Expression = global.glass.Expression;
glass_JSONMergePatch = global.glass.JSONMergePatch;
glass_JSONPointer = global.glass.JSONPointer;
glass_Observable = global.glass.Observable;
glass_Component = global.glass.Component;
delete allTests._init_;
}
allTests._init_();
glass._init_();
glass.Expression._init_();
glass.JSONMergePatch._init_();
glass.JSONPointer._init_();
glass.Observable._init_();
glass.Component._init_();
glass.Container._init_();
glass.Expression._parser._init_();
}).call(glass)",
"www/includes.html": "<script src='/js/String.js'></script>
<script src='/js/glass.js'></script>
<script src='/js/glass/Expression.js'></script>
<script src='/js/glass/JSONMergePatch.js'></script>
<script src='/js/glass/JSONPointer.js'></script>
<script src='/js/glass/Observable.js'></script>
<script src='/js/glass/Component.js'></script>
<script src='/js/glass/Container.js'></script>
<script src='/js/glass/Expression/_parser.js'></script>
<script src='/js/glass/allTests.js'></script>
"
}
} | {
options: {
input: {
dir: "runtime",
match: /\.(coffee|pegjs)$/
},
output: {
dir: "www/js"
},
script: {
includes: "www/includes.html",
prefix: "/js/"
},
module: {
main: "glass.js",
prefix: "./www/js/"
},
debug: "buildlog.html",
test: "glass.allTests",
addon: {
pregenerate: {
addUri: function(schema) {
var content, type, typeName, _ref2, _ref3;
_ref2 = schema.types;
for (typeName in _ref2) {
type = _ref2[typeName];
content = type.content;
if (content.extension) {
continue;
}
if ((_ref3 = content.uri) == null) {
content.uri = "global:/" + (content.path.replace(/\./g, '/'));
}
}
return schema;
}
}
},
namespace: ""
},
types: {
String: {
source: "extension: true
properties:
\tstartsWith: (s) -> @slice(0,s.length) is s
\tendsWith: (s) -> @slice(-s.length) is s
\tcontains: (s) -> @indexOf(s) >= 0
\ttoArray: () -> @split ''",
input: "runtime\\String.coffee",
content: {
extension: true,
properties: {
startsWith: {
value: function(s) {
return this.slice(0, s.length) === s;
},
name: "startsWith"
},
endsWith: {
value: function(s) {
return this.slice( - s.length) === s;
},
name: "endsWith"
},
contains: {
value: function(s) {
return this.indexOf(s) >= 0;
},
name: "contains"
},
toArray: {
value: function() {
return this.split('');
},
name: "toArray"
}
},
name: "String",
path: "String",
namespace: "",
require: {},
import: {},
implements: {
String: true
}
},
isFirst: true,
output: "www\\js\\String.js"
},
glass: {
source: "require:
\tString: true
# runtime type tests
isFunction: (object) -> object? and typeof object is 'function'
isString: (object) -> object?.constructor is String
isArray: (object) -> Array.isArray object
isBoolean: (object) -> object? and typeof object is 'boolean'
isNumber: (object) -> object? and typeof object is 'number'
isObject: (object) -> typeof object is 'object'
isPlainObject: (object) -> object?.constructor is Object
isPrototype: (object) -> object? and object is object.constructor.prototype
isDate: (object) -> object?.constructor is Date
isPrimitive: (object) -> isString(object) or isBoolean(object) or isNumber(object) or isDate(object)
isPrivate: (property) -> property?[0] is '_'
# generic utility functions
values: (object) -> (value for key, value of object)
# generic patch method, uses patch method built into object if present
patch: (target, pathAndPatch...) ->
patch = JSONMergePatch.create.apply null, pathAndPatch
if isFunction target?.patch
target.patch patch
else
glass.JSONMergePatch.apply target, patch
# testing assertions
_getStackLocationInfo: (e, depth) ->
line = e.stack?.split('
')[depth]
return null unless line?
match = /\\(([\\w\\W]*?):(\\d+):(\\d+)\\)/.exec line
return {
file: match[1]
line: parseInt match[2]
column: parseInt match[3]
}
_throwAssertionFailure: (message) ->
try
throw new Error \"Assertion failed: \" + message
catch e
info = _getStackLocationInfo e, 3
if info?
_dumpFile info.file, info.line - 2, info.line + 2, info.line
throw e
_dumpFile: (file, from=1, to, highlight) ->
fs = require 'fs'
return unless fs?
try
content = fs.readFileSync(file).toString()
catch e
content = \"Source not found: #{e}\"
console.log '------------------------------------------------'
console.log file
console.log '------------------------------------------------'
number = 1
if content?
lines = content.split /
|
/
to ?= lines.length
for line in lines
lineNumber = number++
if lineNumber >= from and lineNumber <= to
num = String lineNumber
while num.length < 3
num += ' '
if lineNumber is highlight
`console.log(\"\\033[91m\" + num + \": \" + line + \"\\033[0m\");`
else
`console.log(num + \": \" + line);`
console.log '------------------------------------------------'
assert: (a) ->
_throwAssertionFailure JSON.stringify(a) unless a
assertTrue: (a) ->
_throwAssertionFailure JSON.stringify(a) + \" != true\" unless a is true
assertEquals: (a, b) ->
if JSON.stringify(a) isnt JSON.stringify(b)
_throwAssertionFailure JSON.stringify(a) + ' != ' + JSON.stringify(b)
# gets a unique string identifier for any object
getId:
do: ->
counter = 0
(a) ->
if a is null
return '__null__'
if a is undefined
return '__undefined__'
if typeof a is 'object' or typeof a is 'function'
return a.id ?= '__' + (counter++) + '__'
# 12 == \"12\" under this technique
return a.toString()
getType: (path) ->
array = if isArray path then path else path.split '.'
value = global
for step in path when value?
value = value[step]
throw new Error \"Type not found: #{path}\" unless isFunction value
value
test:
values: ->
assertEquals values({a:1,b:3,c:2}), [1,3,2]
patch: ->
x = {a:{foo:1,bar:3},b:2}
patch x, 'a', 'foo', 5
assertEquals x.a.foo, 5
",
input: "runtime\\glass.coffee",
content: {
require: {
String: "String"
},
isFunction: function(object) {
return (object != null) && typeof object === 'function';
},
isString: function(object) {
return (object != null ? object.constructor: void 0) === String;
},
isArray: function(object) {
return Array.isArray(object);
},
isBoolean: function(object) {
return (object != null) && typeof object === 'boolean';
},
isNumber: function(object) {
return (object != null) && typeof object === 'number';
},
isObject: function(object) {
return typeof object === 'object';
},
isPlainObject: function(object) {
return (object != null ? object.constructor: void 0) === Object;
},
isPrototype: function(object) {
return (object != null) && object === object.constructor.prototype;
},
isDate: function(object) {
return (object != null ? object.constructor: void 0) === Date;
},
isPrimitive: function(object) {
return isString(object) || isBoolean(object) || isNumber(object) || isDate(object);
},
isPrivate: function(property) {
return (property != null ? property[0] : void 0) === '_';
},
values: function(object) {
var key, value, _results;
_results = [];
for (key in object) {
value = object[key];
_results.push(value);
}
return _results;
},
patch: function() {
var patch, pathAndPatch, target;
target = arguments[0],
pathAndPatch = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
patch = JSONMergePatch.create.apply(null, pathAndPatch);
if (isFunction(target != null ? target.patch: void 0)) {
return target.patch(patch);
} else {
return glass.JSONMergePatch.apply(target, patch);
}
},
assert: function(a) {
if (!a) {
return _throwAssertionFailure(JSON.stringify(a));
}
},
assertTrue: function(a) {
if (a !== true) {
return _throwAssertionFailure(JSON.stringify(a) + " != true");
}
},
assertEquals: function(a, b) {
if (JSON.stringify(a) !== JSON.stringify(b)) {
return _throwAssertionFailure(JSON.stringify(a) + ' != ' + JSON.stringify(b));
}
},
getId: {
do: function() {
var counter;
counter = 0;
return function(a) {
var _ref;
if (a === null) {
return '__null__';
}
if (a === void 0) {
return '__undefined__';
}
if (typeof a === 'object' || typeof a === 'function') {
return (_ref = a.id) != null ? _ref: a.id = '__' + (counter++) + '__';
}
return a.toString();
};
}
},
getType: function(path) {
var array, step, value, _i, _len;
array = isArray(path) ? path: path.split('.');
value = global;
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
if (!isFunction(value)) {
throw new Error("Type not found: " + path);
}
return value;
},
test: {
values: function() {
return assertEquals(values({
a: 1,
b: 3,
c: 2
}), [1, 3, 2]);
},
patch: function() {
var x;
x = {
a: {
foo: 1,
bar: 3
},
b: 2
};
patch(x, 'a', 'foo', 5);
return assertEquals(x.a.foo, 5);
}
},
name: "glass",
path: "glass",
namespace: "",
import: {
"glass.JSONMergePatch": "JSONMergePatch",
"glass.isFunction": "isFunction",
"glass.isString": "isString",
"glass.isArray": "isArray",
"glass.isBoolean": "isBoolean",
"glass.isNumber": "isNumber",
"glass.isDate": "isDate",
"glass.values": "values",
"glass.patch": "patch",
"glass._getStackLocationInfo": "_getStackLocationInfo",
"glass._throwAssertionFailure": "_throwAssertionFailure",
"glass._dumpFile": "_dumpFile",
"glass.assertEquals": "assertEquals"
},
uri: "global:/glass"
},
output: "www\\js\\glass.js"
},
"glass.Expression": {
source: "constructor: (op, args) ->
@op = op
@args = args if args?
@
properties:
op:
type: 'string'
args:
type: 'array'
test: ->
return
peg = require 'pegjs'
fs = require 'fs'
parserSource = fs.readFileSync 'runtime/glass/Expression/_parser.pegjs', 'utf8'
parser = peg.buildParser parserSource
tests =
\"a.b.c\": {op:\"get\",args:[{op:\"get\",args:[{op:\"ref\",args:[\"a\"]},\"b\"]},\"c\"]}
\"a.1\": {op:\"get\",args:[{op:\"ref\",args:[\"a\"]},1]}
\"true\": true
\"false\": false
\"45.8\": 45.8
\"(45.8)\": 45.8
\"((45.8))\": 45.8
\"alpha\": {op:\"ref\",args:[\"alpha\"]}
\"35 + true * 2\": {op:\"+\", args:[35, {op:\"*\", args:[true,2]}]}
\" 5 * ( 2 + 2 ) \": {op:\"*\", args:[5, {op:\"+\", args:[2,2]}]}
\" ! ! true\": {op:\"!\",args:[{op:\"!\",args:[true]}]}
\"5 + -x\": {op:\"+\",args:[5,{op:\"-\",args:[{op:\"ref\",args:[\"x\"]}]}]}
\"true == 5 >= 2\": {op:\"==\",args:[true,{op:\">=\",args:[5,2]}]}
\"1 or 2 and 3\": {op:\"or\",args:[1,{op:\"and\",args:[2,3]}]}
\"1 ? 2 : 3\": {op:\"?:\",args:[1,2,3]}
\"1 ? 2 : 3 ? 4 : 5\" : {op:\"?:\",args:[1,2,{op:\"?:\",args:[3,4,5]}]}
\"a()(1,2)\" : {op:\"call\",args:[{op:\"call\",args:[{op:\"ref\",args:[\"a\"]},[]]},[1,2]]}
\"@\" : {op:\"this\"}
\"@foo\" : {op:\"get\",args:[{op:\"this\"},\"foo\"]}
'\"hello\"': \"hello\"
'\"\\\\t\\
\\
\\\\b\\\\\\\\foo\\\\\\/\"' : \"\\t
\\b\\\\foo\\/\"
\"[]\": {op:\"array\",args:[]}
\"[1,2]\": {op:\"array\",args:[1,2]}
\"[1+2]\": {op:\"array\",args:[{op:\"+\",args:[1,2]}]}
\"{}\": {op:\"object\",args:[]}
'{\"a\":2}': {op:\"object\",args:[[\"a\",2]]}
'{\"a\":2,\"b\":1+2}': {op:\"object\",args:[[\"a\",2],[\"b\",{op:\"+\",args:[1,2]}]]}
'@\"alpha\"': {op:\"get\",args:[{op:\"this\"},\"alpha\"]}
'*': {op:\"values\",args:[]}
'*.*': {op:\"values\",args:[{op:\"values\",args:[]}]}
\"foo.*\": {op:\"values\",args:[{op:\"ref\",args:[\"foo\"]}]}
\"..\": {op:\"ancestor\",args:[1]}
\"...\": {op:\"ancestor\",args:[2]}
\"@*{1+2}\": {op:\"eval\",args:[{op:\"values\",args:[{op:\"this\"}]},{op:\"+\",args:[1,2]}]}
\"/\": {op:\"root\"}
\"/foo\": {op:\"get\",args:[{op:\"root\"},\"foo\"]}
\"/*\": {op:\"values\",args:[{op:\"root\"}]}
for text, expected of tests
result = parser.parse text
if JSON.stringify(result) is JSON.stringify(expected)
console.log 'Pass: ' + text
else
console.log text, JSON.stringify result
return
",
input: "runtime\\glass\\Expression.coffee",
content: {
constructor: function(op, args) {
this.op = op;
if (args != null) {
this.args = args;
}
return this;
},
properties: {
op: {
type: "string",
name: "op",
writable: true
},
args: {
type: "array",
name: "args",
writable: true
}
},
test: function() {
var expected, fs, parser, parserSource, peg, result, tests, text;
return;
peg = require('pegjs');
fs = require('fs');
parserSource = fs.readFileSync('runtime/glass/Expression/_parser.pegjs', 'utf8');
parser = peg.buildParser(parserSource);
tests = {
"a.b.c": {
op: "get",
args: [{
op: "get",
args: [{
op: "ref",
args: ["a"]
},
"b"]
},
"c"]
},
"a.1": {
op: "get",
args: [{
op: "ref",
args: ["a"]
},
1]
},
"true": true,
"false": false,
"45.8": 45.8,
"(45.8)": 45.8,
"((45.8))": 45.8,
"alpha": {
op: "ref",
args: ["alpha"]
},
"35 + true * 2": {
op: "+",
args: [35, {
op: "*",
args: [true, 2]
}]
},
" 5 * ( 2 + 2 ) ": {
op: "*",
args: [5, {
op: "+",
args: [2, 2]
}]
},
" ! ! true": {
op: "!",
args: [{
op: "!",
args: [true]
}]
},
"5 + -x": {
op: "+",
args: [5, {
op: "-",
args: [{
op: "ref",
args: ["x"]
}]
}]
},
"true == 5 >= 2": {
op: "==",
args: [true, {
op: ">=",
args: [5, 2]
}]
},
"1 or 2 and 3": {
op: "or",
args: [1, {
op: "and",
args: [2, 3]
}]
},
"1 ? 2 : 3": {
op: "?:",
args: [1, 2, 3]
},
"1 ? 2 : 3 ? 4 : 5": {
op: "?:",
args: [1, 2, {
op: "?:",
args: [3, 4, 5]
}]
},
"a()(1,2)": {
op: "call",
args: [{
op: "call",
args: [{
op: "ref",
args: ["a"]
},
[]]
},
[1, 2]]
},
"@": {
op: "this"
},
"@foo": {
op: "get",
args: [{
op: "this"
},
"foo"]
},
'"hello"': "hello",
'"\\t
\\b\\\\foo\\\/"': "\t
\b\\foo\/",
"[]": {
op: "array",
args: []
},
"[1,2]": {
op: "array",
args: [1, 2]
},
"[1+2]": {
op: "array",
args: [{
op: "+",
args: [1, 2]
}]
},
"{}": {
op: "object",
args: []
},
'{"a":2}': {
op: "object",
args: [["a", 2]]
},
'{"a":2,"b":1+2}': {
op: "object",
args: [["a", 2], ["b", {
op: "+",
args: [1, 2]
}]]
},
'@"alpha"': {
op: "get",
args: [{
op: "this"
},
"alpha"]
},
'*': {
op: "values",
args: []
},
'*.*': {
op: "values",
args: [{
op: "values",
args: []
}]
},
"foo.*": {
op: "values",
args: [{
op: "ref",
args: ["foo"]
}]
},
"..": {
op: "ancestor",
args: [1]
},
"...": {
op: "ancestor",
args: [2]
},
"@*{1+2}": {
op: "eval",
args: [{
op: "values",
args: [{
op: "this"
}]
},
{
op: "+",
args: [1, 2]
}]
},
"/": {
op: "root"
},
"/foo": {
op: "get",
args: [{
op: "root"
},
"foo"]
},
"/*": {
op: "values",
args: [{
op: "root"
}]
}
};
for (text in tests) {
expected = tests[text];
result = parser.parse(text);
if (JSON.stringify(result) === JSON.stringify(expected)) {
console.log('Pass: ' + text);
} else {
console.log(text, JSON.stringify(result));
}
}
},
name: "Expression",
path: "glass.Expression",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.Expression._parser": "_parser",
"glass.values": "values"
},
implements: {
"glass.Expression": true
},
uri: "global:/glass/Expression"
},
output: "www\\js\\glass\\Expression.js"
},
"glass.JSONMergePatch": {
source: "
# applies a patch to the target object and returns the resulting target
apply: (target, patch) ->
if target? and target isnt patch and isPlainObject(patch) and not isPrimitive(target)
for key, value of patch
if value is undefined
delete target[key]
else
target[key] = apply target[key], patch[key]
return target
else
return patch
# (path1, path2, path3.., patch) ->
create: ->
if arguments.length is 1
return arguments[0]
result = {}
current = result
for arg, i in arguments when i + 1 < arguments.length
last = i + 2 is arguments.length
current = current[arg] = if last then arguments[arguments.length-1] else {}
result
test: ->
assertEquals {a:{b:12}}, create 'a', 'b', 12
assertEquals {a:3}, apply({a:1,b:2}, {a:3,b:undefined})
",
input: "runtime\\glass\\JSONMergePatch.coffee",
content: {
apply: function(target, patch) {
var key, value;
if ((target != null) && target !== patch && isPlainObject(patch) && !isPrimitive(target)) {
for (key in patch) {
value = patch[key];
if (value === void 0) {
delete target[key];
} else {
target[key] = apply(target[key], patch[key]);
}
}
return target;
} else {
return patch;
}
},
create: function() {
var arg, current, i, last, result, _i, _len;
if (arguments.length === 1) {
return arguments[0];
}
result = {};
current = result;
for (i = _i = 0, _len = arguments.length; _i < _len; i = ++_i) {
arg = arguments[i];
if (! (i + 1 < arguments.length)) {
continue;
}
last = i + 2 === arguments.length;
current = current[arg] = last ? arguments[arguments.length - 1] : {};
}
return result;
},
test: function() {
assertEquals({
a: {
b: 12
}
},
create('a', 'b', 12));
return assertEquals({
a: 3
},
apply({
a: 1,
b: 2
},
{
a: 3,
b: void 0
}));
},
name: "JSONMergePatch",
path: "glass.JSONMergePatch",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONMergePatch.apply": "apply",
"glass.JSONMergePatch.create": "create",
"glass.isPlainObject": "isPlainObject",
"glass.isPrimitive": "isPrimitive",
"glass.patch": "patch",
"glass.assertEquals": "assertEquals"
},
uri: "global:/glass/JSONMergePatch"
},
output: "www\\js\\glass\\JSONMergePatch.js"
},
"glass.JSONPointer": {
source: "# json pointer implementation as per
# http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-05
_decodeStep: (step) -> step.replace(/~1/g, '/').replace(/~0/g, '~')
_getLastStep: (pointer) ->
_decodeStep pointer.substring(pointer.lastIndexOf('/') + 1)
_getParent: (pointer) ->
if not pointer?.length
null
else
pointer.substring(0, pointer.lastIndexOf('/'))
toArray: (pointer) ->
for step in pointer.substring(1).split('/')
_decodeStep step
get: (doc, pointer) ->
value = doc
if pointer.length
path = toArray pointer
for step in path when value?
value = value[step]
value
set: (doc, pointer, value) ->
parentPointer = _getParent pointer
if parentPointer?
parent = get doc, parentPointer
lastStep = _getLastStep pointer
parent[lastStep] = value
value
test: ->
assertEquals _getParent(\"/a/b/c\"), \"/a/b\"
assertEquals _getParent(\"/a\"), \"\"
assertEquals _getParent(\"\"), null
assertEquals _getLastStep(\"/a/b/c\"), \"c\"
assertEquals _getLastStep(\"/a~0~1\"), \"a~/\"
assertEquals _getLastStep(\"\"), \"\"
# tests as per spec
doc = {
\"foo\": [\"bar\", \"baz\"],
\"\": 0,
\"a/b\": 1,
\"c%d\": 2,
\"e^f\": 3,
\"g|h\": 4,
\"i\\\\j\": 5,
\"k\\\"l\": 6,
\" \": 7,
\"m~n\": 8
}
assertEquals get(doc, \"\"), doc
assertEquals get(doc, \"/foo\"), [\"bar\", \"baz\"]
assertEquals get(doc, \"/foo/0\"), \"bar\"
assertEquals get(doc, \"/\"), 0
assertEquals get(doc, \"/a~1b\"), 1
assertEquals get(doc, \"/c%d\"), 2
assertEquals get(doc, \"/e^f\"), 3
assertEquals get(doc, \"/g|h\"), 4
assertEquals get(doc, \"/i\\\\j\"), 5
assertEquals get(doc, \"/k\\\"l\"), 6
assertEquals get(doc, \"/ \"), 7
assertEquals get(doc, \"/m~0n\"), 8
# now test set
assertEquals set(doc, \"/\", 10), 10
assertEquals doc[\"\"], 10
assertEquals set(doc, \"/foo/0\", 10), 10
assertEquals doc.foo[0], 10",
input: "runtime\\glass\\JSONPointer.coffee",
content: {
toArray: function(pointer) {
var step, _i, _len, _ref, _results;
_ref = pointer.substring(1).split('/');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
step = _ref[_i];
_results.push(_decodeStep(step));
}
return _results;
},
get: function(doc, pointer) {
var path, step, value, _i, _len;
value = doc;
if (pointer.length) {
path = toArray(pointer);
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
}
return value;
},
set: function(doc, pointer, value) {
var lastStep, parent, parentPointer;
parentPointer = _getParent(pointer);
if (parentPointer != null) {
parent = get(doc, parentPointer);
lastStep = _getLastStep(pointer);
parent[lastStep] = value;
}
return value;
},
test: function() {
var doc;
assertEquals(_getParent("/a/b/c"), "/a/b");
assertEquals(_getParent("/a"), "");
assertEquals(_getParent(""), null);
assertEquals(_getLastStep("/a/b/c"), "c");
assertEquals(_getLastStep("/a~0~1"), "a~/");
assertEquals(_getLastStep(""), "");
doc = {
"foo": ["bar", "baz"],
"": 0,
"a/b": 1,
"c%d": 2,
"e^f": 3,
"g|h": 4,
"i\\j": 5,
"k\"l": 6,
" ": 7,
"m~n": 8
};
assertEquals(get(doc, ""), doc);
assertEquals(get(doc, "/foo"), ["bar", "baz"]);
assertEquals(get(doc, "/foo/0"), "bar");
assertEquals(get(doc, "/"), 0);
assertEquals(get(doc, "/a~1b"), 1);
assertEquals(get(doc, "/c%d"), 2);
assertEquals(get(doc, "/e^f"), 3);
assertEquals(get(doc, "/g|h"), 4);
assertEquals(get(doc, "/i\\j"), 5);
assertEquals(get(doc, "/k\"l"), 6);
assertEquals(get(doc, "/ "), 7);
assertEquals(get(doc, "/m~0n"), 8);
assertEquals(set(doc, "/", 10), 10);
assertEquals(doc[""], 10);
assertEquals(set(doc, "/foo/0", 10), 10);
return assertEquals(doc.foo[0], 10);
},
name: "JSONPointer",
path: "glass.JSONPointer",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONPointer._decodeStep": "_decodeStep",
"glass.JSONPointer._getLastStep": "_getLastStep",
"glass.JSONPointer._getParent": "_getParent",
"glass.JSONPointer.toArray": "toArray",
"glass.JSONPointer.get": "get",
"glass.JSONPointer.set": "set",
"glass.assertEquals": "assertEquals"
},
uri: "global:/glass/JSONPointer"
},
output: "www\\js\\glass\\JSONPointer.js"
},
"glass.Observable": {
source: "properties:
is: (type) -> @constructor.implements[type.path ? type] is true
watchers:
serializable: false
watch: (property, watcher) ->
if isFunction property
watcher = property
property = ''
id = getId watcher
@patch 'watchers', property, id, watcher
# returns a function which will remove the watch
=> @patch 'watchers', property, getId(watcher), undefined
patch: (change) ->
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
try
JSONMergePatch.apply this, change
catch e
console.log e
finally
@notify change
return
notify: (change) ->
if @watchers?
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
for property, watchers of @watchers
if property.length is 0 or change.hasOwnProperty property
changeArg = if property.length is 0 then change else change[property]
for id, watcher of watchers
watcher this, changeArg
return
toJSON: ->
values =
class: @constructor.path
# serialize statically defined properties
for name, property of @constructor.properties
value = @[name]
if property.serializable isnt false and not isFunction(value)
values[name] = value
# serialize custom properties if allowed by schema
if @constructor.additionalProperties isnt false
for own name, value of @ when not isPrivate name
values[name] = value
values
toString: -> @toJSON()
test:
toJSON: ->
# I need this test later
# on a class that actually has serializable properties
a = new Observable
a.x = 12
a.y = ->
a.z = true
assertEquals a, {class:'glass.Observable', x:12,z:true}
watchAll: ->
# we should actually be able to watch ourselves get added to watchers
# this is very meta.
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch watcher
# now make sure we were called with our own watcher
assert watchArgs[0] is a
assert watchArgs[1]?.watchers?[\"\"]?
# reset watchArgs, and watch something else
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assertEquals a.a, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {a:{b:3}}
# now unwatch
unwatch()
# make sure universal watcher is now empty
assertEquals a.watchers[\"\"], {}
# now reset and do a new event, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
watchProperty: ->
# watch a property
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch \"foo\", watcher
# now make sure we were not called
assert watchArgs.length is 0
# reset watchArgs, and watch something else
a.patch \"foo\", \"b\", 3
assertEquals a.foo, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {b:3}
# now reset and do a different property, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
# now unwatch
unwatch()
# make sure we no longer see foo
watchArgs.length = 0
a.patch \"foo\", \"b\", 4
assert watchArgs.length is 0
",
input: "runtime\\glass\\Observable.coffee",
content: {
properties: {
is: {
value: function(type) {
var _ref;
return this.constructor["implements"][(_ref = type.path) != null ? _ref: type] === true;
},
name: "is"
},
watchers: {
serializable: false,
name: "watchers",
writable: true
},
watch: {
value: function(property, watcher) {
var id, _this = this;
if (isFunction(property)) {
watcher = property;
property = '';
}
id = getId(watcher);
this.patch('watchers', property, id, watcher);
return function() {
return _this.patch('watchers', property, getId(watcher), void 0);
};
},
name: "watch"
},
patch: {
value: function(change) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
try {
JSONMergePatch.apply(this, change);
} catch(e) {
console.log(e);
} finally {
this.notify(change);
}
},
name: "patch"
},
notify: {
value: function(change) {
var changeArg, id, property, watcher, watchers, _ref;
if (this.watchers != null) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
_ref = this.watchers;
for (property in _ref) {
watchers = _ref[property];
if (property.length === 0 || change.hasOwnProperty(property)) {
changeArg = property.length === 0 ? change: change[property];
for (id in watchers) {
watcher = watchers[id];
watcher(this, changeArg);
}
}
}
}
},
name: "notify"
},
toJSON: {
value: function() {
var name, property, value, values, _ref;
values = {
"class": this.constructor.path
};
_ref = this.constructor.properties;
for (name in _ref) {
property = _ref[name];
value = this[name];
if (property.serializable !== false && !isFunction(value)) {
values[name] = value;
}
}
if (this.constructor.additionalProperties !== false) {
for (name in this) {
if (!__hasProp.call(this, name)) continue;
value = this[name];
if (!isPrivate(name)) {
values[name] = value;
}
}
}
return values;
},
name: "toJSON"
},
toString: {
value: function() {
return this.toJSON();
},
name: "toString"
}
},
test: {
toJSON: function() {
var a;
a = new Observable;
a.x = 12;
a.y = function() {};
a.z = true;
return assertEquals(a, {
"class": 'glass.Observable',
x: 12,
z: true
});
},
watchAll: function() {
var a, unwatch, watchArgs, watcher, _ref, _ref1;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch(watcher);
assert(watchArgs[0] === a);
assert(((_ref = watchArgs[1]) != null ? (_ref1 = _ref.watchers) != null ? _ref1[""] : void 0 : void 0) != null);
watchArgs.length = 0;
a.patch("a", "b", 3);
assertEquals(a.a, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
a: {
b: 3
}
});
unwatch();
assertEquals(a.watchers[""], {});
watchArgs.length = 0;
a.patch("a", "b", 3);
return assert(watchArgs.length === 0);
},
watchProperty: function() {
var a, unwatch, watchArgs, watcher;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch("foo", watcher);
assert(watchArgs.length === 0);
a.patch("foo", "b", 3);
assertEquals(a.foo, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
b: 3
});
watchArgs.length = 0;
a.patch("a", "b", 3);
assert(watchArgs.length === 0);
unwatch();
watchArgs.length = 0;
a.patch("foo", "b", 4);
return assert(watchArgs.length === 0);
}
},
name: "Observable",
path: "glass.Observable",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONMergePatch": "JSONMergePatch",
"glass.isFunction": "isFunction",
"glass.isPrivate": "isPrivate",
"glass.values": "values",
"glass.patch": "patch",
"glass.assert": "assert",
"glass.assertEquals": "assertEquals",
"glass.getId": "getId"
},
implements: {
"glass.Observable": true
},
uri: "global:/glass/Observable"
},
output: "www\\js\\glass\\Observable.js"
},
"glass.Component": {
source: "extends: 'Observable'
constructor: (properties) ->
@patch properties
# now site ourselves on our parent
if @parent
id = getId @
patch @parent, id, @
@
properties:
id:
description: 'string which uniquely identifies this component within its parent'
type: 'string'
parent:
description: 'the object that contains this component'
serializable: false
type: 'object'
disposed: false
dispose: -> @patch 'disposed', true
notify: (change) ->
Observable.prototype.notify.apply this, arguments
if change?.disposed
# dispose of any disposable children
for id, child of @ when child?.parent is @
child.dispose?()
# remove self from parent
if @id and @parent
patch @parent, @id, undefined
return
test:
lifecycle: ->
parent = new Component
assert not parent.id?
assert not parent.parent?
child = new Component parent:parent
# id should be automatically assigned
assert isString child.id
assert parent is child.parent
assert parent[child.id] is child
assert parent.hasOwnProperty child.id
parent.dispose()
assert child.disposed is true
assert not parent.hasOwnProperty child.id
nonEnumerability: ->
visibleKeys = (key for key of new Component)
assertEquals visibleKeys, []",
input: "runtime\\glass\\Component.coffee",
content: {
extends: ["glass.Observable"],
constructor: function(properties) {
var id;
this.patch(properties);
if (this.parent) {
id = getId(this);
patch(this.parent, id, this);
}
return this;
},
properties: {
id: {
description: "string which uniquely identifies this component within its parent",
type: "string",
name: "id",
writable: true
},
parent: {
description: "the object that contains this component",
serializable: false,
type: "object",
name: "parent",
writable: true
},
disposed: {
value: false,
name: "disposed",
writable: true
},
dispose: {
value: function() {
return this.patch('disposed', true);
},
name: "dispose"
},
notify: {
value: function(change) {
var child, id;
Observable.prototype.notify.apply(this, arguments);
if (change != null ? change.disposed: void 0) {
for (id in this) {
child = this[id];
if ((child != null ? child.parent: void 0) === this) {
if (typeof child.dispose === "function") {
child.dispose();
}
}
}
if (this.id && this.parent) {
patch(this.parent, this.id, void 0);
}
}
},
name: "notify"
}
},
test: {
lifecycle: function() {
var child, parent;
parent = new Component;
assert(!(parent.id != null));
assert(!(parent.parent != null));
child = new Component({
parent: parent
});
assert(isString(child.id));
assert(parent === child.parent);
assert(parent[child.id] === child);
assert(parent.hasOwnProperty(child.id));
parent.dispose();
assert(child.disposed === true);
return assert(!parent.hasOwnProperty(child.id));
},
nonEnumerability: function() {
var key, visibleKeys;
visibleKeys = (function() {
var _results;
_results = [];
for (key in new Component) {
_results.push(key);
}
return _results;
})();
return assertEquals(visibleKeys, []);
}
},
name: "Component",
path: "glass.Component",
namespace: "glass",
require: {
glass: "glass",
"glass.Observable": "Observable"
},
import: {
"glass.Observable": "Observable",
"glass.isString": "isString",
"glass.patch": "patch",
"glass.assert": "assert",
"glass.assertEquals": "assertEquals",
"glass.getId": "getId"
},
implements: {
"glass.Component": true,
"glass.Observable": true
},
uri: "global:/glass/Component"
},
output: "www\\js\\glass\\Component.js"
},
"glass.Container": {
source: "extends: 'Observable'
properties:
watch: ->
unwatch: ->
",
input: "runtime\\glass\\Container.coffee",
content: {
extends: ["glass.Observable"],
properties: {
watch: {
value: function() {},
name: "watch"
},
unwatch: {
value: function() {},
name: "unwatch"
}
},
name: "Container",
path: "glass.Container",
namespace: "glass",
require: {
glass: "glass",
"glass.Observable": "Observable"
},
import: {},
implements: {
"glass.Container": true,
"glass.Observable": true
},
uri: "global:/glass/Container"
},
output: "www\\js\\glass\\Container.js"
},
"glass.Expression._parser": {
source: "{
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e,array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++)
array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
}
start = expression
expression = conditional
conditional = e:or args:(\"?\" b:expression \":\" c:expression {return [b,c];})* {
while (args.length > 0) {
e = expr(\"?:\", [e].concat(args.pop()));
}
return e;
}
or = a:and b:((\"or\") and)* { return joinLeft(a,b); }
and = a:equality b:((\"and\") equality)* { return joinLeft(a,b); }
equality = a:rel b:((\"==\" / \"!=\") rel)* { return joinLeft(a,b); }
rel = a:sum b:((\"<=\" / \">=\" / \"<\" / \">\") sum)* { return joinLeft(a,b); }
sum = a:product b:((\"+\" / \"-\") product)* { return joinLeft(a,b); }
product = a:not b:((\"*\" / \"div\" / \"mod\") not)* { return joinLeft(a,b); }
not = ops:(s op:(\"!\" / \"~\" / \"+\" / \"-\") { return op; })* b:primary { return unaryRight(ops,b); }
primary = s a:(group / literal / path) s { return a; }
group = \"(\" a:expression \")\" { return a; }
literal = s a:(boolean / number / string / array / object) s { return a; }
boolean = a:(\"true\" / \"false\") { return a == \"true\"; }
number = a:([0-9]+ (\".\" [0-9]+)?) { return parseFloat(toString(a)); }
hex = [a-fA-F0-9]
// as per JSON http://www.json.org
string = a:( '\"' (
[\\u0000-\\u0021\\u0023-\\u005c\\u005e-\\uffff] // all unicode chars except \\ and \"
/ (\"\\\\\" (\"\\\"\" / \"\\\\\" / \"\\/\" / \"b\" / \"f\" / \"n\" / \"r\" / \"t\" / (\"u\" hex hex hex hex)))
)* '\"' )
{ return JSON.parse(toString(a)); }
array = \"[\" a:values \"]\" { return expr(\"array\", a); }
values = first:expression? args:(\",\" b:expression {return b;})* {
if (first != \"\") { args.unshift(first); } return args;
}
object = \"{\" a:keyvalues \"}\" { return expr(\"object\", a); }
keyvalue = s a:string s \":\" b:expression { return [a,b]; }
keyvalues = first:keyvalue? rest:(\",\" b:keyvalue {return b;})* {
if (first) { rest.unshift(first); } return rest;
}
ref = a:(\"//\" / \"/\" / \"$\" / \"**\" / \"*\" / \"..\" / \".\") b:slashProperty? {
e = expr(a); if (b) { b.args.unshift(e); e = b; } return e;
}
/ a:id { return expr(\"ref\", [a]); }
id = a:[a-z_]+ b:[a-z_0-9]* { return a.join('') + b.join(''); }
property = \"/\" a:slashProperty { return a; }
/ \"{\" a:expression \"}\" { return expr(\"{}\", [a]); } // locally scoped expression
/ \"[\" a:expression \"]\" { return expr(\"[]\", [a]); } // predicate
slashProperty = a:(id/number/string) { return expr(\"/\", [a]); }
/ a:(\"..\" / \"*\") { return expr(a, []); }
s \"space\" = [ ]* { return ''; }
path = a:root b:step* {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
}
root = a:implicitDotRoot b:dotStep? { return joinPath(a,b); }
/ explicitDotRoot
step = \".\" a:dotStep { return a; }
/ noDotStep
implicitDotRoot = \"/\" { return expr(\"root\"); }
/ \"@\" { return expr(\"this\"); }
/ \".\" a:\".\"+ { return expr(\"ancestor\", [a.length]); }
explicitDotRoot = a:id { return expr(\"ref\", [a]); }
/ \"*\" { return expr(\"values\", []); }
dotStep = a:(id / string / number) { return expr(\"get\", [a]); }
/ \"*\" { return expr(\"values\", []); }
noDotStep = \"{\" a:expression \"}\" { return expr(\"eval\", [a]); }
/ \"[\" a:expression \"]\" { return expr(\"pred\", [a]); }
/ \"(\" a:values \")\" { return expr(\"call\", [a]); }
",
input: "runtime\\glass\\Expression\\_parser.pegjs",
content: {
value: {
parse: function(input, startRule) {
var parseFunctions = {
"conditional": parse_conditional,
"or": parse_or,
"and": parse_and,
"equality": parse_equality,
"rel": parse_rel,
"sum": parse_sum,
"product": parse_product,
"not": parse_not,
"primary": parse_primary,
"group": parse_group,
"literal": parse_literal,
"boolean": parse_boolean,
"number": parse_number,
"hex": parse_hex,
"string": parse_string,
"array": parse_array,
"values": parse_values,
"object": parse_object,
"keyvalue": parse_keyvalue,
"keyvalues": parse_keyvalues,
"ref": parse_ref,
"id": parse_id,
"property": parse_property,
"slashProperty": parse_slashProperty,
"s": parse_s,
"path": parse_path,
"root": parse_root,
"step": parse_step,
"implicitDotRoot": parse_implicitDotRoot,
"explicitDotRoot": parse_explicitDotRoot,
"dotStep": parse_dotStep,
"noDotStep": parse_noDotStep
};
if (startRule !== undefined) {
if (parseFunctions[startRule] === undefined) {
throw new Error("Invalid rule name: " + quote(startRule) + ".");
}
} else {
startRule = "conditional";
}
var pos = 0;
var reportFailures = 0;
var rightmostFailuresPos = 0;
var rightmostFailuresExpected = [];
function padLeft(input, padding, length) {
var result = input;
var padLength = length - input.length;
for (var i = 0; i < padLength; i++) {
result = padding + result;
}
return result;
}
function escape(ch) {
var charCode = ch.charCodeAt(0);
var escapeChar;
var length;
if (charCode <= 0xFF) {
escapeChar = 'x';
length = 2;
} else {
escapeChar = 'u';
length = 4;
}
return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
}
function matchFailed(failure) {
if (pos < rightmostFailuresPos) {
return;
}
if (pos > rightmostFailuresPos) {
rightmostFailuresPos = pos;
rightmostFailuresExpected = [];
}
rightmostFailuresExpected.push(failure);
}
function parse_conditional() {
var result0, result1, result2, result3, result4, result5;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_or();
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, e, args) {
while (args.length > 0) {
e = expr("?:", [e].concat(args.pop()));
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_or() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_and();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_and() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_equality();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_equality() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_rel();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_rel() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_sum();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_sum() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_product();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_product() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_not();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_not() {
var result0, result1, result2;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = [];
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
while (result1 !== null) {
result0.push(result1);
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
}
if (result0 !== null) {
result1 = parse_primary();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, ops, b) {
return unaryRight(ops, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_primary() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_group();
if (result1 === null) {
result1 = parse_literal();
if (result1 === null) {
result1 = parse_path();
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_group() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_literal() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_boolean();
if (result1 === null) {
result1 = parse_number();
if (result1 === null) {
result1 = parse_string();
if (result1 === null) {
result1 = parse_array();
if (result1 === null) {
result1 = parse_object();
}
}
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_boolean() {
var result0;
var pos0;
pos0 = pos;
if (input.substr(pos, 4) === "true") {
result0 = "true";
pos += 4;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"true\"");
}
}
if (result0 === null) {
if (input.substr(pos, 5) === "false") {
result0 = "false";
pos += 5;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"false\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a == "true";
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_number() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
pos2 = pos;
if (input.charCodeAt(pos) === 46) {
result1 = ".";
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result1 !== null) {
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result3 !== null) {
result2 = [];
while (result3 !== null) {
result2.push(result3);
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result2 = null;
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos2;
}
} else {
result1 = null;
pos = pos2;
}
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return parseFloat(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_hex() {
var result0;
if (/^[a-fA-F0-9]/.test(input.charAt(pos))) {
result0 = input.charAt(pos);
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("[a-fA-F0-9]");
}
}
return result0;
}
function parse_string() {
var result0, result1, result2, result3, result4, result5, result6, result7;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 34) {
result0 = "\"";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result0 !== null) {
result1 = [];
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
}
if (result1 !== null) {
if (input.charCodeAt(pos) === 34) {
result2 = "\"";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return JSON.parse(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_array() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("array", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_values() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_conditional();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, args) {
if (first != "") {
args.unshift(first);
}
return args;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_object() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_keyvalues();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("object", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalue() {
var result0, result1, result2, result3, result4;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_string();
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
if (input.charCodeAt(pos) === 58) {
result3 = ":";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result3 !== null) {
result4 = parse_conditional();
if (result4 !== null) {
result0 = [result0, result1, result2, result3, result4];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return [a, b];
})(pos0, result0[1], result0[4]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalues() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_keyvalue();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, rest) {
if (first) {
rest.unshift(first);
}
return rest;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_ref() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.substr(pos, 2) === "//") {
result0 = "//";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"//\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 36) {
result0 = "$";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"$\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "**") {
result0 = "**";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"**\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
}
}
}
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
e = expr(a);
if (b) {
b.args.unshift(e);
e = b;
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_id() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
result1 = [];
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return a.join('') + b.join('');
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_property() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("{}", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("[]", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_slashProperty() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_number();
if (result0 === null) {
result0 = parse_string();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("/", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(a, []);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_s() {
var result0, result1;
var pos0;
reportFailures++;
pos0 = pos;
result0 = [];
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
while (result1 !== null) {
result0.push(result1);
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
}
if (result0 !== null) {
result0 = (function(offset) {
return '';
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
reportFailures--;
if (reportFailures === 0 && result0 === null) {
matchFailed("space");
}
return result0;
}
function parse_path() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_root();
if (result0 !== null) {
result1 = [];
result2 = parse_step();
while (result2 !== null) {
result1.push(result2);
result2 = parse_step();
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_root() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_implicitDotRoot();
if (result0 !== null) {
result1 = parse_dotStep();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinPath(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_explicitDotRoot();
}
return result0;
}
function parse_step() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
result1 = parse_dotStep();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_noDotStep();
}
return result0;
}
function parse_implicitDotRoot() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("root");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 64) {
result0 = "@";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"@\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("this");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result2 !== null) {
result1 = [];
while (result2 !== null) {
result1.push(result2);
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
} else {
result1 = null;
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ancestor", [a.length]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_explicitDotRoot() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_dotStep() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_string();
if (result0 === null) {
result0 = parse_number();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("get", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_noDotStep() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("eval", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("pred", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("call", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function cleanupExpected(expected) {
expected.sort();
var lastExpected = null;
var cleanExpected = [];
for (var i = 0; i < expected.length; i++) {
if (expected[i] !== lastExpected) {
cleanExpected.push(expected[i]);
lastExpected = expected[i];
}
}
return cleanExpected;
}
function computeErrorPosition() {
/*
* The first idea was to use |String.split| to break the input up to the
* error position along newlines and derive the line and column from
* there. However IE's |split| implementation is so broken that it was
* enough to prevent it.
*/
var line = 1;
var column = 1;
var seenCR = false;
for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
var ch = input.charAt(i);
if (ch === "
") {
if (!seenCR) {
line++;
}
column = 1;
seenCR = false;
} else if (ch === "
" || ch === "\u2028" || ch === "\u2029") {
line++;
column = 1;
seenCR = true;
} else {
column++;
seenCR = false;
}
}
return {
line: line,
column: column
};
}
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e, array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++) array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
var result = parseFunctions[startRule]();
/*
* The parser is now in one of the following three states:
*
* 1. The parser successfully parsed the whole input.
*
* - |result !== null|
* - |pos === input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 2. The parser successfully parsed only a part of the input.
*
* - |result !== null|
* - |pos < input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 3. The parser did not successfully parse any part of the input.
*
* - |result === null|
* - |pos === 0|
* - |rightmostFailuresExpected| contains at least one failure
*
* All code following this comment (including called functions) must
* handle these states.
*/
if (result === null || pos !== input.length) {
var offset = Math.max(pos, rightmostFailuresPos);
var found = offset < input.length ? input.charAt(offset) : null;
var errorPosition = computeErrorPosition();
throw new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column);
}
return result;
},
toSource: function() {
return this._source;
},
SyntaxError: function(expected, found, offset, line, column) {
function buildMessage(expected, found) {
var expectedHumanized, foundHumanized;
switch (expected.length) {
case 0:
expectedHumanized = "end of input";
break;
case 1:
expectedHumanized = expected[0];
break;
default:
expectedHumanized = expected.slice(0, expected.length - 1).join(", ") + " or " + expected[expected.length - 1];
}
foundHumanized = found ? quote(found) : "end of input";
return "Expected " + expectedHumanized + " but " + foundHumanized + " found.";
}
this.name = "SyntaxError";
this.expected = expected;
this.found = found;
this.message = buildMessage(expected, found);
this.offset = offset;
this.line = line;
this.column = column;
}
},
name: "_parser",
path: "glass.Expression._parser",
namespace: "glass.Expression",
require: {
"glass.Expression": "Expression"
},
import: {
"glass.values": "values"
},
uri: "global:/glass/Expression/_parser"
},
output: "www\\js\\glass\\Expression\\_parser.js"
},
"glass.allTests": {
content: {
path: "glass.allTests",
name: "allTests",
namespace: "glass",
import: {
glass: "glass",
"glass.Expression": "glass_Expression",
"glass.JSONMergePatch": "glass_JSONMergePatch",
"glass.JSONPointer": "glass_JSONPointer",
"glass.Observable": "glass_Observable",
"glass.Component": "glass_Component"
},
value: function anonymous(callback) {
if (callback == null) {
callback = function(path, result) {
if (result == null) {
console.log("\033[92mPass\033[0m: " + path + "");
} else {
console.log("\033[91mFail\033[0m: " + path + "");
console.log(result.stack || result);
}
}
}
function singleTest(path, test) {
if (test == null) {
callback(path, "test not found");
return;
} else if (typeof test == 'object') {
for (var key in test) singleTest(path + '.' + key, test[key]);
return;
}
try {
callback(path, test());
} catch(e) {
callback(path, e);
}
}
singleTest("glass", glass.test);
singleTest("glass.Expression", glass_Expression.test);
singleTest("glass.JSONMergePatch", glass_JSONMergePatch.test);
singleTest("glass.JSONPointer", glass_JSONPointer.test);
singleTest("glass.Observable", glass_Observable.test);
singleTest("glass.Component", glass_Component.test);
}
},
isLast: true,
output: "www\\js\\glass\\allTests.js"
}
},
output: {
"www\\js\\String.js": "(function() {
var global = (function() {
return this;
})();
if (String.prototype.startsWith == null) {
Object.defineProperty(String.prototype, \"startsWith\", {
value: function(s) {
return this.slice(0, s.length) === s;
},
name: \"startsWith\"
});
}
if (String.prototype.endsWith == null) {
Object.defineProperty(String.prototype, \"endsWith\", {
value: function(s) {
return this.slice( - s.length) === s;
},
name: \"endsWith\"
});
}
if (String.prototype.contains == null) {
Object.defineProperty(String.prototype, \"contains\", {
value: function(s) {
return this.indexOf(s) >= 0;
},
name: \"contains\"
});
}
if (String.prototype.toArray == null) {
Object.defineProperty(String.prototype, \"toArray\", {
value: function() {
return this.split('');
},
name: \"toArray\"
});
}
String._init_ = function() {
delete String._init_;
}
}).call()",
"www\\js\\glass.js": "(function() {
var global = (function() {
return this;
})();
var JSONMergePatch; // assigned during _init_
var isFunction; // assigned during _init_
var isString; // assigned during _init_
var isArray; // assigned during _init_
var isBoolean; // assigned during _init_
var isNumber; // assigned during _init_
var isDate; // assigned during _init_
var values; // assigned during _init_
var patch; // assigned during _init_
var _getStackLocationInfo; // assigned during _init_
var _throwAssertionFailure; // assigned during _init_
var _dumpFile; // assigned during _init_
var assertEquals; // assigned during _init_
var glass = this.glass = {
isFunction: function(object) {
return (object != null) && typeof object === 'function';
},
isString: function(object) {
return (object != null ? object.constructor: void 0) === String;
},
isArray: function(object) {
return Array.isArray(object);
},
isBoolean: function(object) {
return (object != null) && typeof object === 'boolean';
},
isNumber: function(object) {
return (object != null) && typeof object === 'number';
},
isObject: function(object) {
return typeof object === 'object';
},
isPlainObject: function(object) {
return (object != null ? object.constructor: void 0) === Object;
},
isPrototype: function(object) {
return (object != null) && object === object.constructor.prototype;
},
isDate: function(object) {
return (object != null ? object.constructor: void 0) === Date;
},
isPrimitive: function(object) {
return isString(object) || isBoolean(object) || isNumber(object) || isDate(object);
},
isPrivate: function(property) {
return (property != null ? property[0] : void 0) === '_';
},
values: function(object) {
var key, value, _results;
_results = [];
for (key in object) {
value = object[key];
_results.push(value);
}
return _results;
},
patch: function() {
var patch, pathAndPatch, target;
target = arguments[0],
pathAndPatch = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
patch = JSONMergePatch.create.apply(null, pathAndPatch);
if (isFunction(target != null ? target.patch: void 0)) {
return target.patch(patch);
} else {
return glass.JSONMergePatch.apply(target, patch);
}
},
_getStackLocationInfo: function(e, depth) {
var line, match, _ref;
line = (_ref = e.stack) != null ? _ref.split('
')[depth] : void 0;
if (line == null) {
return null;
}
match = /\\(([\\w\\W]*?):(\\d+):(\\d+)\\)/.exec(line);
return {
file: match[1],
line: parseInt(match[2]),
column: parseInt(match[3])
};
},
_throwAssertionFailure: function(message) {
var info;
try {
throw new Error(\"Assertion failed: \" + message);
} catch(e) {
info = _getStackLocationInfo(e, 3);
if (info != null) {
_dumpFile(info.file, info.line - 2, info.line + 2, info.line);
}
throw e;
}
},
_dumpFile: function(file, from, to, highlight) {
var content, fs, line, lineNumber, lines, num, number, _i, _len;
if (from == null) {
from = 1;
}
fs = require('fs');
if (fs == null) {
return;
}
try {
content = fs.readFileSync(file).toString();
} catch(e) {
content = \"Source not found: \" + e;
}
console.log('------------------------------------------------');
console.log(file);
console.log('------------------------------------------------');
number = 1;
if (content != null) {
lines = content.split(/
|
/);
if (to == null) {
to = lines.length;
}
for (_i = 0, _len = lines.length; _i < _len; _i++) {
line = lines[_i];
lineNumber = number++;
if (lineNumber >= from && lineNumber <= to) {
num = String(lineNumber);
while (num.length < 3) {
num += ' ';
}
if (lineNumber === highlight) {
console.log(\"\\033[91m\" + num + \": \" + line + \"\\033[0m\");;
} else {
console.log(num + \": \" + line);;
}
}
}
}
return console.log('------------------------------------------------');
},
assert: function(a) {
if (!a) {
return _throwAssertionFailure(JSON.stringify(a));
}
},
assertTrue: function(a) {
if (a !== true) {
return _throwAssertionFailure(JSON.stringify(a) + \" != true\");
}
},
assertEquals: function(a, b) {
if (JSON.stringify(a) !== JSON.stringify(b)) {
return _throwAssertionFailure(JSON.stringify(a) + ' != ' + JSON.stringify(b));
}
},
getId: (function() {
var counter;
counter = 0;
return function(a) {
var _ref;
if (a === null) {
return '__null__';
}
if (a === void 0) {
return '__undefined__';
}
if (typeof a === 'object' || typeof a === 'function') {
return (_ref = a.id) != null ? _ref: a.id = '__' + (counter++) + '__';
}
return a.toString();
};
})(),
getType: function(path) {
var array, step, value, _i, _len;
array = isArray(path) ? path: path.split('.');
value = global;
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
if (!isFunction(value)) {
throw new Error(\"Type not found: \" + path);
}
return value;
},
test: {
values: function() {
return assertEquals(values({
a: 1,
b: 3,
c: 2
}), [1, 3, 2]);
},
patch: function() {
var x;
x = {
a: {
foo: 1,
bar: 3
},
b: 2
};
patch(x, 'a', 'foo', 5);
return assertEquals(x.a.foo, 5);
}
},
path: \"glass\",
uri: \"global:/glass\"
};
glass._init_ = function() {
JSONMergePatch = global.glass.JSONMergePatch;
isFunction = global.glass.isFunction;
isString = global.glass.isString;
isArray = global.glass.isArray;
isBoolean = global.glass.isBoolean;
isNumber = global.glass.isNumber;
isDate = global.glass.isDate;
values = global.glass.values;
patch = global.glass.patch;
_getStackLocationInfo = global.glass._getStackLocationInfo;
_throwAssertionFailure = global.glass._throwAssertionFailure;
_dumpFile = global.glass._dumpFile;
assertEquals = global.glass.assertEquals;
delete glass._init_;
}
}).call()",
"www\\js\\glass\\Expression.js": "(function() {
var global = (function() {
return this;
})();
var glass = this;
var _parser; // assigned during _init_
var values; // assigned during _init_
var Expression = this.Expression = function Expression(op, args) {
this.op = op;
if (args != null) {
this.args = args;
}
return this;
};
Expression.properties = {
op: {
type: \"string\",
name: \"op\",
writable: true
},
args: {
type: \"array\",
name: \"args\",
writable: true
}
};
Expression.test = function() {
var expected, fs, parser, parserSource, peg, result, tests, text;
return;
peg = require('pegjs');
fs = require('fs');
parserSource = fs.readFileSync('runtime/glass/Expression/_parser.pegjs', 'utf8');
parser = peg.buildParser(parserSource);
tests = {
\"a.b.c\": {
op: \"get\",
args: [{
op: \"get\",
args: [{
op: \"ref\",
args: [\"a\"]
},
\"b\"]
},
\"c\"]
},
\"a.1\": {
op: \"get\",
args: [{
op: \"ref\",
args: [\"a\"]
},
1]
},
\"true\": true,
\"false\": false,
\"45.8\": 45.8,
\"(45.8)\": 45.8,
\"((45.8))\": 45.8,
\"alpha\": {
op: \"ref\",
args: [\"alpha\"]
},
\"35 + true * 2\": {
op: \"+\",
args: [35, {
op: \"*\",
args: [true, 2]
}]
},
\" 5 * ( 2 + 2 ) \": {
op: \"*\",
args: [5, {
op: \"+\",
args: [2, 2]
}]
},
\" ! ! true\": {
op: \"!\",
args: [{
op: \"!\",
args: [true]
}]
},
\"5 + -x\": {
op: \"+\",
args: [5, {
op: \"-\",
args: [{
op: \"ref\",
args: [\"x\"]
}]
}]
},
\"true == 5 >= 2\": {
op: \"==\",
args: [true, {
op: \">=\",
args: [5, 2]
}]
},
\"1 or 2 and 3\": {
op: \"or\",
args: [1, {
op: \"and\",
args: [2, 3]
}]
},
\"1 ? 2 : 3\": {
op: \"?:\",
args: [1, 2, 3]
},
\"1 ? 2 : 3 ? 4 : 5\": {
op: \"?:\",
args: [1, 2, {
op: \"?:\",
args: [3, 4, 5]
}]
},
\"a()(1,2)\": {
op: \"call\",
args: [{
op: \"call\",
args: [{
op: \"ref\",
args: [\"a\"]
},
[]]
},
[1, 2]]
},
\"@\": {
op: \"this\"
},
\"@foo\": {
op: \"get\",
args: [{
op: \"this\"
},
\"foo\"]
},
'\"hello\"': \"hello\",
'\"\\\\t\\
\\
\\\\b\\\\\\\\foo\\\\\\/\"': \"\\t
\\b\\\\foo\\/\",
\"[]\": {
op: \"array\",
args: []
},
\"[1,2]\": {
op: \"array\",
args: [1, 2]
},
\"[1+2]\": {
op: \"array\",
args: [{
op: \"+\",
args: [1, 2]
}]
},
\"{}\": {
op: \"object\",
args: []
},
'{\"a\":2}': {
op: \"object\",
args: [[\"a\", 2]]
},
'{\"a\":2,\"b\":1+2}': {
op: \"object\",
args: [[\"a\", 2], [\"b\", {
op: \"+\",
args: [1, 2]
}]]
},
'@\"alpha\"': {
op: \"get\",
args: [{
op: \"this\"
},
\"alpha\"]
},
'*': {
op: \"values\",
args: []
},
'*.*': {
op: \"values\",
args: [{
op: \"values\",
args: []
}]
},
\"foo.*\": {
op: \"values\",
args: [{
op: \"ref\",
args: [\"foo\"]
}]
},
\"..\": {
op: \"ancestor\",
args: [1]
},
\"...\": {
op: \"ancestor\",
args: [2]
},
\"@*{1+2}\": {
op: \"eval\",
args: [{
op: \"values\",
args: [{
op: \"this\"
}]
},
{
op: \"+\",
args: [1, 2]
}]
},
\"/\": {
op: \"root\"
},
\"/foo\": {
op: \"get\",
args: [{
op: \"root\"
},
\"foo\"]
},
\"/*\": {
op: \"values\",
args: [{
op: \"root\"
}]
}
};
for (text in tests) {
expected = tests[text];
result = parser.parse(text);
if (JSON.stringify(result) === JSON.stringify(expected)) {
console.log('Pass: ' + text);
} else {
console.log(text, JSON.stringify(result));
}
}
};
Expression.path = \"glass.Expression\";
Expression.implements = {
\"glass.Expression\": true
};
Expression.uri = \"global:/glass/Expression\";
Object.defineProperties(Expression.prototype, Expression.properties);
Expression._init_ = function() {
_parser = global.glass.Expression._parser;
values = global.glass.values;
delete Expression._init_;
}
}).call(glass)",
"www\\js\\glass\\JSONMergePatch.js": "(function() {
var global = (function() {
return this;
})();
var glass = this;
var apply; // assigned during _init_
var create; // assigned during _init_
var isPlainObject; // assigned during _init_
var isPrimitive; // assigned during _init_
var patch; // assigned during _init_
var assertEquals; // assigned during _init_
var JSONMergePatch = this.JSONMergePatch = {
apply: function(target, patch) {
var key, value;
if ((target != null) && target !== patch && isPlainObject(patch) && !isPrimitive(target)) {
for (key in patch) {
value = patch[key];
if (value === void 0) {
delete target[key];
} else {
target[key] = apply(target[key], patch[key]);
}
}
return target;
} else {
return patch;
}
},
create: function() {
var arg, current, i, last, result, _i, _len;
if (arguments.length === 1) {
return arguments[0];
}
result = {};
current = result;
for (i = _i = 0, _len = arguments.length; _i < _len; i = ++_i) {
arg = arguments[i];
if (! (i + 1 < arguments.length)) {
continue;
}
last = i + 2 === arguments.length;
current = current[arg] = last ? arguments[arguments.length - 1] : {};
}
return result;
},
test: function() {
assertEquals({
a: {
b: 12
}
},
create('a', 'b', 12));
return assertEquals({
a: 3
},
apply({
a: 1,
b: 2
},
{
a: 3,
b: void 0
}));
},
path: \"glass.JSONMergePatch\",
uri: \"global:/glass/JSONMergePatch\"
};
JSONMergePatch._init_ = function() {
apply = global.glass.JSONMergePatch.apply;
create = global.glass.JSONMergePatch.create;
isPlainObject = global.glass.isPlainObject;
isPrimitive = global.glass.isPrimitive;
patch = global.glass.patch;
assertEquals = global.glass.assertEquals;
delete JSONMergePatch._init_;
}
}).call(glass)",
"www\\js\\glass\\JSONPointer.js": "(function() {
var global = (function() {
return this;
})();
var glass = this;
var _decodeStep; // assigned during _init_
var _getLastStep; // assigned during _init_
var _getParent; // assigned during _init_
var toArray; // assigned during _init_
var get; // assigned during _init_
var set; // assigned during _init_
var assertEquals; // assigned during _init_
var JSONPointer = this.JSONPointer = {
_decodeStep: function(step) {
return step.replace(/~1/g, '/').replace(/~0/g, '~');
},
_getLastStep: function(pointer) {
return _decodeStep(pointer.substring(pointer.lastIndexOf('/') + 1));
},
_getParent: function(pointer) {
if (! (pointer != null ? pointer.length: void 0)) {
return null;
} else {
return pointer.substring(0, pointer.lastIndexOf('/'));
}
},
toArray: function(pointer) {
var step, _i, _len, _ref, _results;
_ref = pointer.substring(1).split('/');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
step = _ref[_i];
_results.push(_decodeStep(step));
}
return _results;
},
get: function(doc, pointer) {
var path, step, value, _i, _len;
value = doc;
if (pointer.length) {
path = toArray(pointer);
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
}
return value;
},
set: function(doc, pointer, value) {
var lastStep, parent, parentPointer;
parentPointer = _getParent(pointer);
if (parentPointer != null) {
parent = get(doc, parentPointer);
lastStep = _getLastStep(pointer);
parent[lastStep] = value;
}
return value;
},
test: function() {
var doc;
assertEquals(_getParent(\"/a/b/c\"), \"/a/b\");
assertEquals(_getParent(\"/a\"), \"\");
assertEquals(_getParent(\"\"), null);
assertEquals(_getLastStep(\"/a/b/c\"), \"c\");
assertEquals(_getLastStep(\"/a~0~1\"), \"a~/\");
assertEquals(_getLastStep(\"\"), \"\");
doc = {
\"foo\": [\"bar\", \"baz\"],
\"\": 0,
\"a/b\": 1,
\"c%d\": 2,
\"e^f\": 3,
\"g|h\": 4,
\"i\\\\j\": 5,
\"k\\\"l\": 6,
\" \": 7,
\"m~n\": 8
};
assertEquals(get(doc, \"\"), doc);
assertEquals(get(doc, \"/foo\"), [\"bar\", \"baz\"]);
assertEquals(get(doc, \"/foo/0\"), \"bar\");
assertEquals(get(doc, \"/\"), 0);
assertEquals(get(doc, \"/a~1b\"), 1);
assertEquals(get(doc, \"/c%d\"), 2);
assertEquals(get(doc, \"/e^f\"), 3);
assertEquals(get(doc, \"/g|h\"), 4);
assertEquals(get(doc, \"/i\\\\j\"), 5);
assertEquals(get(doc, \"/k\\\"l\"), 6);
assertEquals(get(doc, \"/ \"), 7);
assertEquals(get(doc, \"/m~0n\"), 8);
assertEquals(set(doc, \"/\", 10), 10);
assertEquals(doc[\"\"], 10);
assertEquals(set(doc, \"/foo/0\", 10), 10);
return assertEquals(doc.foo[0], 10);
},
path: \"glass.JSONPointer\",
uri: \"global:/glass/JSONPointer\"
};
JSONPointer._init_ = function() {
_decodeStep = global.glass.JSONPointer._decodeStep;
_getLastStep = global.glass.JSONPointer._getLastStep;
_getParent = global.glass.JSONPointer._getParent;
toArray = global.glass.JSONPointer.toArray;
get = global.glass.JSONPointer.get;
set = global.glass.JSONPointer.set;
assertEquals = global.glass.assertEquals;
delete JSONPointer._init_;
}
}).call(glass)",
"www\\js\\glass\\Observable.js": "(function() {
var global = (function() {
return this;
})();
var glass = this;
var JSONMergePatch; // assigned during _init_
var isFunction; // assigned during _init_
var isPrivate; // assigned during _init_
var values; // assigned during _init_
var patch; // assigned during _init_
var assert; // assigned during _init_
var assertEquals; // assigned during _init_
var getId; // assigned during _init_
var Observable = this.Observable = function Observable(properties) {
var key;
if (properties != null) {
for (key in properties) {
this[key] = properties[key];
}
}
}
Observable.properties = {
is: {
value: function(type) {
var _ref;
return this.constructor[\"implements\"][(_ref = type.path) != null ? _ref: type] === true;
},
name: \"is\"
},
watchers: {
serializable: false,
name: \"watchers\",
writable: true
},
watch: {
value: function(property, watcher) {
var id, _this = this;
if (isFunction(property)) {
watcher = property;
property = '';
}
id = getId(watcher);
this.patch('watchers', property, id, watcher);
return function() {
return _this.patch('watchers', property, getId(watcher), void 0);
};
},
name: \"watch\"
},
patch: {
value: function(change) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
try {
JSONMergePatch.apply(this, change);
} catch(e) {
console.log(e);
} finally {
this.notify(change);
}
},
name: \"patch\"
},
notify: {
value: function(change) {
var changeArg, id, property, watcher, watchers, _ref;
if (this.watchers != null) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
_ref = this.watchers;
for (property in _ref) {
watchers = _ref[property];
if (property.length === 0 || change.hasOwnProperty(property)) {
changeArg = property.length === 0 ? change: change[property];
for (id in watchers) {
watcher = watchers[id];
watcher(this, changeArg);
}
}
}
}
},
name: \"notify\"
},
toJSON: {
value: function() {
var name, property, value, values, _ref;
values = {
\"class\": this.constructor.path
};
_ref = this.constructor.properties;
for (name in _ref) {
property = _ref[name];
value = this[name];
if (property.serializable !== false && !isFunction(value)) {
values[name] = value;
}
}
if (this.constructor.additionalProperties !== false) {
for (name in this) {
if (!__hasProp.call(this, name)) continue;
value = this[name];
if (!isPrivate(name)) {
values[name] = value;
}
}
}
return values;
},
name: \"toJSON\"
},
toString: {
value: function() {
return this.toJSON();
},
name: \"toString\"
}
};
Observable.test = {
toJSON: function() {
var a;
a = new Observable;
a.x = 12;
a.y = function() {};
a.z = true;
return assertEquals(a, {
\"class\": 'glass.Observable',
x: 12,
z: true
});
},
watchAll: function() {
var a, unwatch, watchArgs, watcher, _ref, _ref1;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch(watcher);
assert(watchArgs[0] === a);
assert(((_ref = watchArgs[1]) != null ? (_ref1 = _ref.watchers) != null ? _ref1[\"\"] : void 0 : void 0) != null);
watchArgs.length = 0;
a.patch(\"a\", \"b\", 3);
assertEquals(a.a, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
a: {
b: 3
}
});
unwatch();
assertEquals(a.watchers[\"\"], {});
watchArgs.length = 0;
a.patch(\"a\", \"b\", 3);
return assert(watchArgs.length === 0);
},
watchProperty: function() {
var a, unwatch, watchArgs, watcher;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch(\"foo\", watcher);
assert(watchArgs.length === 0);
a.patch(\"foo\", \"b\", 3);
assertEquals(a.foo, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
b: 3
});
watchArgs.length = 0;
a.patch(\"a\", \"b\", 3);
assert(watchArgs.length === 0);
unwatch();
watchArgs.length = 0;
a.patch(\"foo\", \"b\", 4);
return assert(watchArgs.length === 0);
}
};
Observable.path = \"glass.Observable\";
Observable.implements = {
\"glass.Observable\": true
};
Observable.uri = \"global:/glass/Observable\";
Object.defineProperties(Observable.prototype, Observable.properties);
Observable._init_ = function() {
JSONMergePatch = global.glass.JSONMergePatch;
isFunction = global.glass.isFunction;
isPrivate = global.glass.isPrivate;
values = global.glass.values;
patch = global.glass.patch;
assert = global.glass.assert;
assertEquals = global.glass.assertEquals;
getId = global.glass.getId;
delete Observable._init_;
}
}).call(glass)",
"www\\js\\glass\\Component.js": "(function() {
var global = (function() {
return this;
})();
var glass = this;
var Observable = global.glass.Observable;
var Observable; // assigned during _init_
var isString; // assigned during _init_
var patch; // assigned during _init_
var assert; // assigned during _init_
var assertEquals; // assigned during _init_
var getId; // assigned during _init_
var Component = this.Component = function Component(properties) {
var id;
this.patch(properties);
if (this.parent) {
id = getId(this);
patch(this.parent, id, this);
}
return this;
};
Component.properties = {
id: {
description: \"string which uniquely identifies this component within its parent\",
type: \"string\",
name: \"id\",
writable: true
},
parent: {
description: \"the object that contains this component\",
serializable: false,
type: \"object\",
name: \"parent\",
writable: true
},
disposed: {
value: false,
name: \"disposed\",
writable: true
},
dispose: {
value: function() {
return this.patch('disposed', true);
},
name: \"dispose\"
},
notify: {
value: function(change) {
var child, id;
Observable.prototype.notify.apply(this, arguments);
if (change != null ? change.disposed: void 0) {
for (id in this) {
child = this[id];
if ((child != null ? child.parent: void 0) === this) {
if (typeof child.dispose === \"function\") {
child.dispose();
}
}
}
if (this.id && this.parent) {
patch(this.parent, this.id, void 0);
}
}
},
name: \"notify\"
}
};
Component.test = {
lifecycle: function() {
var child, parent;
parent = new Component;
assert(!(parent.id != null));
assert(!(parent.parent != null));
child = new Component({
parent: parent
});
assert(isString(child.id));
assert(parent === child.parent);
assert(parent[child.id] === child);
assert(parent.hasOwnProperty(child.id));
parent.dispose();
assert(child.disposed === true);
return assert(!parent.hasOwnProperty(child.id));
},
nonEnumerability: function() {
var key, visibleKeys;
visibleKeys = (function() {
var _results;
_results = [];
for (key in new Component) {
_results.push(key);
}
return _results;
})();
return assertEquals(visibleKeys, []);
}
};
Component.path = \"glass.Component\";
Component.implements = {
\"glass.Component\": true,
\"glass.Observable\": true
};
Component.uri = \"global:/glass/Component\";
(function() {
var baseTypes = [Observable];
var i, j, baseType, a, b;
for (i = 0; i < baseTypes.length; i++) {
baseType = baseTypes[i];
for (key in baseType.properties) {
a = Component.properties[key];
b = baseType.properties[key];
if (a != null && b != null && a.constructor === Object && b.constructor === Object) {
for (j in b) {
if (!a.hasOwnProperty(j)) a[j] = b[j];
}
} else if (!Component.properties.hasOwnProperty(key)) {
Component.properties[key] = b;
}
}
}
})();
Object.defineProperties(Component.prototype, Component.properties);
Component._init_ = function() {
Observable = global.glass.Observable;
isString = global.glass.isString;
patch = global.glass.patch;
assert = global.glass.assert;
assertEquals = global.glass.assertEquals;
getId = global.glass.getId;
delete Component._init_;
}
}).call(glass)",
"www\\js\\glass\\Container.js": "(function() {
var global = (function() {
return this;
})();
var glass = this;
var Observable = global.glass.Observable;
var Container = this.Container = function Container(properties) {
var key;
if (properties != null) {
for (key in properties) {
this[key] = properties[key];
}
}
}
Container.properties = {
watch: {
value: function() {},
name: \"watch\"
},
unwatch: {
value: function() {},
name: \"unwatch\"
}
};
Container.path = \"glass.Container\";
Container.implements = {
\"glass.Container\": true,
\"glass.Observable\": true
};
Container.uri = \"global:/glass/Container\";
(function() {
var baseTypes = [Observable];
var i, j, baseType, a, b;
for (i = 0; i < baseTypes.length; i++) {
baseType = baseTypes[i];
for (key in baseType.properties) {
a = Container.properties[key];
b = baseType.properties[key];
if (a != null && b != null && a.constructor === Object && b.constructor === Object) {
for (j in b) {
if (!a.hasOwnProperty(j)) a[j] = b[j];
}
} else if (!Container.properties.hasOwnProperty(key)) {
Container.properties[key] = b;
}
}
}
})();
Object.defineProperties(Container.prototype, Container.properties);
Container._init_ = function() {
delete Container._init_;
}
}).call(glass)",
"www\\js\\glass\\Expression\\_parser.js": "(function() {
var global = (function() {
return this;
})();
var Expression = this;
var values; // assigned during _init_
var _parser = this._parser = {
parse: function(input, startRule) {
var parseFunctions = {
\"conditional\": parse_conditional,
\"or\": parse_or,
\"and\": parse_and,
\"equality\": parse_equality,
\"rel\": parse_rel,
\"sum\": parse_sum,
\"product\": parse_product,
\"not\": parse_not,
\"primary\": parse_primary,
\"group\": parse_group,
\"literal\": parse_literal,
\"boolean\": parse_boolean,
\"number\": parse_number,
\"hex\": parse_hex,
\"string\": parse_string,
\"array\": parse_array,
\"values\": parse_values,
\"object\": parse_object,
\"keyvalue\": parse_keyvalue,
\"keyvalues\": parse_keyvalues,
\"ref\": parse_ref,
\"id\": parse_id,
\"property\": parse_property,
\"slashProperty\": parse_slashProperty,
\"s\": parse_s,
\"path\": parse_path,
\"root\": parse_root,
\"step\": parse_step,
\"implicitDotRoot\": parse_implicitDotRoot,
\"explicitDotRoot\": parse_explicitDotRoot,
\"dotStep\": parse_dotStep,
\"noDotStep\": parse_noDotStep
};
if (startRule !== undefined) {
if (parseFunctions[startRule] === undefined) {
throw new Error(\"Invalid rule name: \" + quote(startRule) + \".\");
}
} else {
startRule = \"conditional\";
}
var pos = 0;
var reportFailures = 0;
var rightmostFailuresPos = 0;
var rightmostFailuresExpected = [];
function padLeft(input, padding, length) {
var result = input;
var padLength = length - input.length;
for (var i = 0; i < padLength; i++) {
result = padding + result;
}
return result;
}
function escape(ch) {
var charCode = ch.charCodeAt(0);
var escapeChar;
var length;
if (charCode <= 0xFF) {
escapeChar = 'x';
length = 2;
} else {
escapeChar = 'u';
length = 4;
}
return '\\\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
}
function matchFailed(failure) {
if (pos < rightmostFailuresPos) {
return;
}
if (pos > rightmostFailuresPos) {
rightmostFailuresPos = pos;
rightmostFailuresExpected = [];
}
rightmostFailuresExpected.push(failure);
}
function parse_conditional() {
var result0, result1, result2, result3, result4, result5;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_or();
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = \"?\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"?\\\"\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = \":\";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed(\"\\\":\\\"\");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = \"?\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"?\\\"\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = \":\";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed(\"\\\":\\\"\");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, e, args) {
while (args.length > 0) {
e = expr(\"?:\", [e].concat(args.pop()));
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_or() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_and();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === \"or\") {
result2 = \"or\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"or\\\"\");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === \"or\") {
result2 = \"or\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"or\\\"\");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_and() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_equality();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 3) === \"and\") {
result2 = \"and\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"and\\\"\");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 3) === \"and\") {
result2 = \"and\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"and\\\"\");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_equality() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_rel();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === \"==\") {
result2 = \"==\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"==\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \"!=\") {
result2 = \"!=\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"!=\\\"\");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === \"==\") {
result2 = \"==\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"==\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \"!=\") {
result2 = \"!=\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"!=\\\"\");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_rel() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_sum();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === \"<=\") {
result2 = \"<=\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"<=\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \">=\") {
result2 = \">=\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\">=\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = \"<\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"<\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = \">\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\">\\\"\");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === \"<=\") {
result2 = \"<=\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"<=\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \">=\") {
result2 = \">=\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\">=\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = \"<\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"<\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = \">\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\">\\\"\");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_sum() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_product();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = \"+\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"+\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \"-\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"-\\\"\");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = \"+\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"+\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \"-\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"-\\\"\");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_product() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_not();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = \"*\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"*\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \"div\") {
result2 = \"div\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"div\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \"mod\") {
result2 = \"mod\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"mod\\\"\");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = \"*\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"*\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \"div\") {
result2 = \"div\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"div\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \"mod\") {
result2 = \"mod\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"mod\\\"\");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_not() {
var result0, result1, result2;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = [];
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = \"!\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"!\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = \"~\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"~\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = \"+\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"+\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \"-\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"-\\\"\");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
while (result1 !== null) {
result0.push(result1);
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = \"!\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"!\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = \"~\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"~\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = \"+\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"+\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \"-\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"-\\\"\");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
}
if (result0 !== null) {
result1 = parse_primary();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, ops, b) {
return unaryRight(ops, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_primary() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_group();
if (result1 === null) {
result1 = parse_literal();
if (result1 === null) {
result1 = parse_path();
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_group() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = \"(\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"(\\\"\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = \")\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\")\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_literal() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_boolean();
if (result1 === null) {
result1 = parse_number();
if (result1 === null) {
result1 = parse_string();
if (result1 === null) {
result1 = parse_array();
if (result1 === null) {
result1 = parse_object();
}
}
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_boolean() {
var result0;
var pos0;
pos0 = pos;
if (input.substr(pos, 4) === \"true\") {
result0 = \"true\";
pos += 4;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"true\\\"\");
}
}
if (result0 === null) {
if (input.substr(pos, 5) === \"false\") {
result0 = \"false\";
pos += 5;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"false\\\"\");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a == \"true\";
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_number() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\"[0-9]\");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\"[0-9]\");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
pos2 = pos;
if (input.charCodeAt(pos) === 46) {
result1 = \".\";
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\"\\\".\\\"\");
}
}
if (result1 !== null) {
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"[0-9]\");
}
}
if (result3 !== null) {
result2 = [];
while (result3 !== null) {
result2.push(result3);
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"[0-9]\");
}
}
}
} else {
result2 = null;
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos2;
}
} else {
result1 = null;
pos = pos2;
}
result1 = result1 !== null ? result1: \"\";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return parseFloat(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_hex() {
var result0;
if (/^[a-fA-F0-9]/.test(input.charAt(pos))) {
result0 = input.charAt(pos);
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"[a-fA-F0-9]\");
}
}
return result0;
}
function parse_string() {
var result0, result1, result2, result3, result4, result5, result6, result7;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 34) {
result0 = \"\\\"\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\"\\\"\");
}
}
if (result0 !== null) {
result1 = [];
if (/^[\\0-!#-\\\\^-\\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"[\\\\0-!#-\\\\\\\\^-\\\\uFFFF]\");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = \"\\\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\\\\\"\");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = \"\\\"\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\"\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = \"\\\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\\\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = \"/\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"/\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = \"b\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"b\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = \"f\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"f\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = \"n\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"n\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = \"r\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"r\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = \"t\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"t\\\"\");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = \"u\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"u\\\"\");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[\\0-!#-\\\\^-\\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"[\\\\0-!#-\\\\\\\\^-\\\\uFFFF]\");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = \"\\\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\\\\\"\");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = \"\\\"\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\"\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = \"\\\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\\\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = \"/\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"/\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = \"b\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"b\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = \"f\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"f\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = \"n\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"n\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = \"r\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"r\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = \"t\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"t\\\"\");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = \"u\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"u\\\"\");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
}
if (result1 !== null) {
if (input.charCodeAt(pos) === 34) {
result2 = \"\\\"\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\"\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return JSON.parse(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_array() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = \"[\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"[\\\"\");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = \"]\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"]\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"array\", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_values() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_conditional();
result0 = result0 !== null ? result0: \"\";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \",\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\",\\\"\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \",\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\",\\\"\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, args) {
if (first != \"\") {
args.unshift(first);
}
return args;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_object() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = \"{\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"{\\\"\");
}
}
if (result0 !== null) {
result1 = parse_keyvalues();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = \"}\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"}\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"object\", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalue() {
var result0, result1, result2, result3, result4;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_string();
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
if (input.charCodeAt(pos) === 58) {
result3 = \":\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\":\\\"\");
}
}
if (result3 !== null) {
result4 = parse_conditional();
if (result4 !== null) {
result0 = [result0, result1, result2, result3, result4];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return [a, b];
})(pos0, result0[1], result0[4]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalues() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_keyvalue();
result0 = result0 !== null ? result0: \"\";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \",\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\",\\\"\");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \",\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\",\\\"\");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, rest) {
if (first) {
rest.unshift(first);
}
return rest;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_ref() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.substr(pos, 2) === \"//\") {
result0 = \"//\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"//\\\"\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 47) {
result0 = \"/\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"/\\\"\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 36) {
result0 = \"$\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"$\\\"\");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === \"**\") {
result0 = \"**\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"**\\\"\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = \"*\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"*\\\"\");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === \"..\") {
result0 = \"..\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"..\\\"\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 46) {
result0 = \".\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\".\\\"\");
}
}
}
}
}
}
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
result1 = result1 !== null ? result1: \"\";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
e = expr(a);
if (b) {
b.args.unshift(e);
e = b;
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"ref\", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_id() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\"[a-z_]\");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\"[a-z_]\");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
result1 = [];
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"[a-z_0-9]\");
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"[a-z_0-9]\");
}
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return a.join('') + b.join('');
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_property() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = \"/\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"/\\\"\");
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = \"{\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"{\\\"\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = \"}\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"}\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"{}\", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = \"[\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"[\\\"\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = \"]\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"]\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"[]\", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_slashProperty() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_number();
if (result0 === null) {
result0 = parse_string();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"/\", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.substr(pos, 2) === \"..\") {
result0 = \"..\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"..\\\"\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = \"*\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"*\\\"\");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(a, []);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_s() {
var result0, result1;
var pos0;
reportFailures++;
pos0 = pos;
result0 = [];
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\"[ ]\");
}
}
while (result1 !== null) {
result0.push(result1);
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\"[ ]\");
}
}
}
if (result0 !== null) {
result0 = (function(offset) {
return '';
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
reportFailures--;
if (reportFailures === 0 && result0 === null) {
matchFailed(\"space\");
}
return result0;
}
function parse_path() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_root();
if (result0 !== null) {
result1 = [];
result2 = parse_step();
while (result2 !== null) {
result1.push(result2);
result2 = parse_step();
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_root() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_implicitDotRoot();
if (result0 !== null) {
result1 = parse_dotStep();
result1 = result1 !== null ? result1: \"\";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinPath(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_explicitDotRoot();
}
return result0;
}
function parse_step() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = \".\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\".\\\"\");
}
}
if (result0 !== null) {
result1 = parse_dotStep();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_noDotStep();
}
return result0;
}
function parse_implicitDotRoot() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = \"/\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"/\\\"\");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr(\"root\");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 64) {
result0 = \"@\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"@\\\"\");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr(\"this\");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = \".\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\".\\\"\");
}
}
if (result0 !== null) {
if (input.charCodeAt(pos) === 46) {
result2 = \".\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\".\\\"\");
}
}
if (result2 !== null) {
result1 = [];
while (result2 !== null) {
result1.push(result2);
if (input.charCodeAt(pos) === 46) {
result2 = \".\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\".\\\"\");
}
}
}
} else {
result1 = null;
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"ancestor\", [a.length]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_explicitDotRoot() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"ref\", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = \"*\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"*\\\"\");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr(\"values\", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_dotStep() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_string();
if (result0 === null) {
result0 = parse_number();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"get\", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = \"*\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"*\\\"\");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr(\"values\", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_noDotStep() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = \"{\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"{\\\"\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = \"}\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"}\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"eval\", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = \"[\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"[\\\"\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = \"]\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"]\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"pred\", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = \"(\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"(\\\"\");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = \")\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\")\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"call\", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function cleanupExpected(expected) {
expected.sort();
var lastExpected = null;
var cleanExpected = [];
for (var i = 0; i < expected.length; i++) {
if (expected[i] !== lastExpected) {
cleanExpected.push(expected[i]);
lastExpected = expected[i];
}
}
return cleanExpected;
}
function computeErrorPosition() {
/*
* The first idea was to use |String.split| to break the input up to the
* error position along newlines and derive the line and column from
* there. However IE's |split| implementation is so broken that it was
* enough to prevent it.
*/
var line = 1;
var column = 1;
var seenCR = false;
for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
var ch = input.charAt(i);
if (ch === \"
\") {
if (!seenCR) {
line++;
}
column = 1;
seenCR = false;
} else if (ch === \"
\" || ch === \"\\u2028\" || ch === \"\\u2029\") {
line++;
column = 1;
seenCR = true;
} else {
column++;
seenCR = false;
}
}
return {
line: line,
column: column
};
}
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e, array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++) array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
var result = parseFunctions[startRule]();
/*
* The parser is now in one of the following three states:
*
* 1. The parser successfully parsed the whole input.
*
* - |result !== null|
* - |pos === input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 2. The parser successfully parsed only a part of the input.
*
* - |result !== null|
* - |pos < input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 3. The parser did not successfully parse any part of the input.
*
* - |result === null|
* - |pos === 0|
* - |rightmostFailuresExpected| contains at least one failure
*
* All code following this comment (including called functions) must
* handle these states.
*/
if (result === null || pos !== input.length) {
var offset = Math.max(pos, rightmostFailuresPos);
var found = offset < input.length ? input.charAt(offset) : null;
var errorPosition = computeErrorPosition();
throw new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column);
}
return result;
},
toSource: function() {
return this._source;
},
SyntaxError: function(expected, found, offset, line, column) {
function buildMessage(expected, found) {
var expectedHumanized, foundHumanized;
switch (expected.length) {
case 0:
expectedHumanized = \"end of input\";
break;
case 1:
expectedHumanized = expected[0];
break;
default:
expectedHumanized = expected.slice(0, expected.length - 1).join(\", \") + \" or \" + expected[expected.length - 1];
}
foundHumanized = found ? quote(found) : \"end of input\";
return \"Expected \" + expectedHumanized + \" but \" + foundHumanized + \" found.\";
}
this.name = \"SyntaxError\";
this.expected = expected;
this.found = found;
this.message = buildMessage(expected, found);
this.offset = offset;
this.line = line;
this.column = column;
},
_source: \"(function(){
/*
* Generated by PEG.js 0.7.0.
*
* http://pegjs.majda.cz/
*/
function quote(s) {
/*
* ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a
* string literal except for the closing quote character, backslash,
* carriage return, line separator, paragraph separator, and line feed.
* Any character may appear in the form of an escape sequence.
*
* For portability, we also escape escape all control and non-ASCII
* characters. Note that \\\"\\\\0\\\" and \\\"\\\\v\\\" escape sequences are not used
* because JSHint does not like the first and IE the second.
*/
return '\\\"' + s
.replace(/\\\\\\\\/g, '\\\\\\\\\\\\\\\\') // backslash
.replace(/\\\"/g, '\\\\\\\\\\\"') // closing quote character
.replace(/\\\\x08/g, '\\\\\\\\b') // backspace
.replace(/\\\\t/g, '\\\\\\\\t') // horizontal tab
.replace(/\\
/g, '\\\\\\
') // line feed
.replace(/\\\\f/g, '\\\\\\\\f') // form feed
.replace(/\\
/g, '\\\\\\
') // carriage return
.replace(/[\\\\x00-\\\\x07\\\\x0B\\\\x0E-\\\\x1F\\\\x80-\\\\uFFFF]/g, escape)
+ '\\\"';
}
var result = {
/*
* Parses the input with a generated parser. If the parsing is successfull,
* returns a value explicitly or implicitly specified by the grammar from
* which the parser was generated (see |PEG.buildParser|). If the parsing is
* unsuccessful, throws |PEG.parser.SyntaxError| describing the error.
*/
parse: function(input, startRule) {
var parseFunctions = {
\\\"conditional\\\": parse_conditional,
\\\"or\\\": parse_or,
\\\"and\\\": parse_and,
\\\"equality\\\": parse_equality,
\\\"rel\\\": parse_rel,
\\\"sum\\\": parse_sum,
\\\"product\\\": parse_product,
\\\"not\\\": parse_not,
\\\"primary\\\": parse_primary,
\\\"group\\\": parse_group,
\\\"literal\\\": parse_literal,
\\\"boolean\\\": parse_boolean,
\\\"number\\\": parse_number,
\\\"hex\\\": parse_hex,
\\\"string\\\": parse_string,
\\\"array\\\": parse_array,
\\\"values\\\": parse_values,
\\\"object\\\": parse_object,
\\\"keyvalue\\\": parse_keyvalue,
\\\"keyvalues\\\": parse_keyvalues,
\\\"ref\\\": parse_ref,
\\\"id\\\": parse_id,
\\\"property\\\": parse_property,
\\\"slashProperty\\\": parse_slashProperty,
\\\"s\\\": parse_s,
\\\"path\\\": parse_path,
\\\"root\\\": parse_root,
\\\"step\\\": parse_step,
\\\"implicitDotRoot\\\": parse_implicitDotRoot,
\\\"explicitDotRoot\\\": parse_explicitDotRoot,
\\\"dotStep\\\": parse_dotStep,
\\\"noDotStep\\\": parse_noDotStep
};
if (startRule !== undefined) {
if (parseFunctions[startRule] === undefined) {
throw new Error(\\\"Invalid rule name: \\\" + quote(startRule) + \\\".\\\");
}
} else {
startRule = \\\"conditional\\\";
}
var pos = 0;
var reportFailures = 0;
var rightmostFailuresPos = 0;
var rightmostFailuresExpected = [];
function padLeft(input, padding, length) {
var result = input;
var padLength = length - input.length;
for (var i = 0; i < padLength; i++) {
result = padding + result;
}
return result;
}
function escape(ch) {
var charCode = ch.charCodeAt(0);
var escapeChar;
var length;
if (charCode <= 0xFF) {
escapeChar = 'x';
length = 2;
} else {
escapeChar = 'u';
length = 4;
}
return '\\\\\\\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
}
function matchFailed(failure) {
if (pos < rightmostFailuresPos) {
return;
}
if (pos > rightmostFailuresPos) {
rightmostFailuresPos = pos;
rightmostFailuresExpected = [];
}
rightmostFailuresExpected.push(failure);
}
function parse_conditional() {
var result0, result1, result2, result3, result4, result5;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_or();
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = \\\"?\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"?\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = \\\":\\\";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\":\\\\\\\"\\\");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {return [b,c];})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = \\\"?\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"?\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = \\\":\\\";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\":\\\\\\\"\\\");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {return [b,c];})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, e, args) {
while (args.length > 0) {
e = expr(\\\"?:\\\", [e].concat(args.pop()));
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_or() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_and();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === \\\"or\\\") {
result2 = \\\"or\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"or\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === \\\"or\\\") {
result2 = \\\"or\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"or\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return joinLeft(a,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_and() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_equality();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 3) === \\\"and\\\") {
result2 = \\\"and\\\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"and\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 3) === \\\"and\\\") {
result2 = \\\"and\\\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"and\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return joinLeft(a,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_equality() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_rel();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === \\\"==\\\") {
result2 = \\\"==\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"==\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \\\"!=\\\") {
result2 = \\\"!=\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"!=\\\\\\\"\\\");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === \\\"==\\\") {
result2 = \\\"==\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"==\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \\\"!=\\\") {
result2 = \\\"!=\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"!=\\\\\\\"\\\");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return joinLeft(a,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_rel() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_sum();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === \\\"<=\\\") {
result2 = \\\"<=\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"<=\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \\\">=\\\") {
result2 = \\\">=\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\">=\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = \\\"<\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"<\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = \\\">\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\">\\\\\\\"\\\");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === \\\"<=\\\") {
result2 = \\\"<=\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"<=\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \\\">=\\\") {
result2 = \\\">=\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\">=\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = \\\"<\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"<\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = \\\">\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\">\\\\\\\"\\\");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return joinLeft(a,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_sum() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_product();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = \\\"+\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"+\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \\\"-\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"-\\\\\\\"\\\");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = \\\"+\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"+\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \\\"-\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"-\\\\\\\"\\\");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return joinLeft(a,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_product() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_not();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = \\\"*\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"*\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \\\"div\\\") {
result2 = \\\"div\\\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"div\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \\\"mod\\\") {
result2 = \\\"mod\\\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"mod\\\\\\\"\\\");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = \\\"*\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"*\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \\\"div\\\") {
result2 = \\\"div\\\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"div\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \\\"mod\\\") {
result2 = \\\"mod\\\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"mod\\\\\\\"\\\");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return joinLeft(a,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_not() {
var result0, result1, result2;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = [];
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = \\\"!\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"!\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = \\\"~\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"~\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = \\\"+\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"+\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \\\"-\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"-\\\\\\\"\\\");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) { return op; })(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
while (result1 !== null) {
result0.push(result1);
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = \\\"!\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"!\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = \\\"~\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"~\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = \\\"+\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"+\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \\\"-\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"-\\\\\\\"\\\");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) { return op; })(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
}
if (result0 !== null) {
result1 = parse_primary();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, ops, b) { return unaryRight(ops,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_primary() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_group();
if (result1 === null) {
result1 = parse_literal();
if (result1 === null) {
result1 = parse_path();
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return a; })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_group() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = \\\"(\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"(\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = \\\")\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\")\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return a; })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_literal() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_boolean();
if (result1 === null) {
result1 = parse_number();
if (result1 === null) {
result1 = parse_string();
if (result1 === null) {
result1 = parse_array();
if (result1 === null) {
result1 = parse_object();
}
}
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return a; })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_boolean() {
var result0;
var pos0;
pos0 = pos;
if (input.substr(pos, 4) === \\\"true\\\") {
result0 = \\\"true\\\";
pos += 4;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"true\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.substr(pos, 5) === \\\"false\\\") {
result0 = \\\"false\\\";
pos += 5;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"false\\\\\\\"\\\");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) { return a == \\\"true\\\"; })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_number() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\\\"[0-9]\\\");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\\\"[0-9]\\\");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
pos2 = pos;
if (input.charCodeAt(pos) === 46) {
result1 = \\\".\\\";
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\".\\\\\\\"\\\");
}
}
if (result1 !== null) {
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"[0-9]\\\");
}
}
if (result3 !== null) {
result2 = [];
while (result3 !== null) {
result2.push(result3);
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"[0-9]\\\");
}
}
}
} else {
result2 = null;
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos2;
}
} else {
result1 = null;
pos = pos2;
}
result1 = result1 !== null ? result1 : \\\"\\\";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return parseFloat(toString(a)); })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_hex() {
var result0;
if (/^[a-fA-F0-9]/.test(input.charAt(pos))) {
result0 = input.charAt(pos);
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"[a-fA-F0-9]\\\");
}
}
return result0;
}
function parse_string() {
var result0, result1, result2, result3, result4, result5, result6, result7;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 34) {
result0 = \\\"\\\\\\\"\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = [];
if (/^[\\\\0-!#-\\\\\\\\^-\\\\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"[\\\\\\\\0-!#-\\\\\\\\\\\\\\\\^-\\\\\\\\uFFFF]\\\");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = \\\"\\\\\\\\\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\"\\\");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = \\\"\\\\\\\"\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = \\\"\\\\\\\\\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = \\\"/\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"/\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = \\\"b\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"b\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = \\\"f\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"f\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = \\\"n\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"n\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = \\\"r\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"r\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = \\\"t\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"t\\\\\\\"\\\");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = \\\"u\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"u\\\\\\\"\\\");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[\\\\0-!#-\\\\\\\\^-\\\\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"[\\\\\\\\0-!#-\\\\\\\\\\\\\\\\^-\\\\\\\\uFFFF]\\\");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = \\\"\\\\\\\\\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\"\\\");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = \\\"\\\\\\\"\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = \\\"\\\\\\\\\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = \\\"/\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"/\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = \\\"b\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"b\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = \\\"f\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"f\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = \\\"n\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"n\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = \\\"r\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"r\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = \\\"t\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"t\\\\\\\"\\\");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = \\\"u\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"u\\\\\\\"\\\");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
}
if (result1 !== null) {
if (input.charCodeAt(pos) === 34) {
result2 = \\\"\\\\\\\"\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return JSON.parse(toString(a)); })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_array() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = \\\"[\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"[\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = \\\"]\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"]\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"array\\\", a); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_values() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_conditional();
result0 = result0 !== null ? result0 : \\\"\\\";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \\\",\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\",\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {return b;})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \\\",\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\",\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {return b;})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, args) {
if (first != \\\"\\\") { args.unshift(first); } return args;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_object() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = \\\"{\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"{\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_keyvalues();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = \\\"}\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"}\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"object\\\", a); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalue() {
var result0, result1, result2, result3, result4;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_string();
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
if (input.charCodeAt(pos) === 58) {
result3 = \\\":\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\":\\\\\\\"\\\");
}
}
if (result3 !== null) {
result4 = parse_conditional();
if (result4 !== null) {
result0 = [result0, result1, result2, result3, result4];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return [a,b]; })(pos0, result0[1], result0[4]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalues() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_keyvalue();
result0 = result0 !== null ? result0 : \\\"\\\";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \\\",\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\",\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {return b;})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \\\",\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\",\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {return b;})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, rest) {
if (first) { rest.unshift(first); } return rest;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_ref() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.substr(pos, 2) === \\\"//\\\") {
result0 = \\\"//\\\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"//\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 47) {
result0 = \\\"/\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"/\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 36) {
result0 = \\\"$\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"$\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === \\\"**\\\") {
result0 = \\\"**\\\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"**\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = \\\"*\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"*\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === \\\"..\\\") {
result0 = \\\"..\\\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"..\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 46) {
result0 = \\\".\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\".\\\\\\\"\\\");
}
}
}
}
}
}
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
result1 = result1 !== null ? result1 : \\\"\\\";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
e = expr(a); if (b) { b.args.unshift(e); e = b; } return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"ref\\\", [a]); })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_id() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\\\"[a-z_]\\\");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\\\"[a-z_]\\\");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
result1 = [];
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"[a-z_0-9]\\\");
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"[a-z_0-9]\\\");
}
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return a.join('') + b.join(''); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_property() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = \\\"/\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"/\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return a; })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = \\\"{\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"{\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = \\\"}\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"}\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"{}\\\", [a]); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = \\\"[\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"[\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = \\\"]\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"]\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"[]\\\", [a]); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_slashProperty() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_number();
if (result0 === null) {
result0 = parse_string();
}
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"/\\\", [a]); })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.substr(pos, 2) === \\\"..\\\") {
result0 = \\\"..\\\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"..\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = \\\"*\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"*\\\\\\\"\\\");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(a, []); })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_s() {
var result0, result1;
var pos0;
reportFailures++;
pos0 = pos;
result0 = [];
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\\\"[ ]\\\");
}
}
while (result1 !== null) {
result0.push(result1);
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\\\"[ ]\\\");
}
}
}
if (result0 !== null) {
result0 = (function(offset) { return ''; })(pos0);
}
if (result0 === null) {
pos = pos0;
}
reportFailures--;
if (reportFailures === 0 && result0 === null) {
matchFailed(\\\"space\\\");
}
return result0;
}
function parse_path() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_root();
if (result0 !== null) {
result1 = [];
result2 = parse_step();
while (result2 !== null) {
result1.push(result2);
result2 = parse_step();
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_root() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_implicitDotRoot();
if (result0 !== null) {
result1 = parse_dotStep();
result1 = result1 !== null ? result1 : \\\"\\\";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return joinPath(a,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_explicitDotRoot();
}
return result0;
}
function parse_step() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = \\\".\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\".\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_dotStep();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return a; })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_noDotStep();
}
return result0;
}
function parse_implicitDotRoot() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = \\\"/\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"/\\\\\\\"\\\");
}
}
if (result0 !== null) {
result0 = (function(offset) { return expr(\\\"root\\\"); })(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 64) {
result0 = \\\"@\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"@\\\\\\\"\\\");
}
}
if (result0 !== null) {
result0 = (function(offset) { return expr(\\\"this\\\"); })(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = \\\".\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\".\\\\\\\"\\\");
}
}
if (result0 !== null) {
if (input.charCodeAt(pos) === 46) {
result2 = \\\".\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\".\\\\\\\"\\\");
}
}
if (result2 !== null) {
result1 = [];
while (result2 !== null) {
result1.push(result2);
if (input.charCodeAt(pos) === 46) {
result2 = \\\".\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\".\\\\\\\"\\\");
}
}
}
} else {
result1 = null;
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"ancestor\\\", [a.length]); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_explicitDotRoot() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"ref\\\", [a]); })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = \\\"*\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"*\\\\\\\"\\\");
}
}
if (result0 !== null) {
result0 = (function(offset) { return expr(\\\"values\\\", []); })(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_dotStep() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_string();
if (result0 === null) {
result0 = parse_number();
}
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"get\\\", [a]); })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = \\\"*\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"*\\\\\\\"\\\");
}
}
if (result0 !== null) {
result0 = (function(offset) { return expr(\\\"values\\\", []); })(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_noDotStep() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = \\\"{\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"{\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = \\\"}\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"}\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"eval\\\", [a]); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = \\\"[\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"[\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = \\\"]\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"]\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"pred\\\", [a]); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = \\\"(\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"(\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = \\\")\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\")\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"call\\\", [a]); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function cleanupExpected(expected) {
expected.sort();
var lastExpected = null;
var cleanExpected = [];
for (var i = 0; i < expected.length; i++) {
if (expected[i] !== lastExpected) {
cleanExpected.push(expected[i]);
lastExpected = expected[i];
}
}
return cleanExpected;
}
function computeErrorPosition() {
/*
* The first idea was to use |String.split| to break the input up to the
* error position along newlines and derive the line and column from
* there. However IE's |split| implementation is so broken that it was
* enough to prevent it.
*/
var line = 1;
var column = 1;
var seenCR = false;
for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
var ch = input.charAt(i);
if (ch === \\\"\\
\\\") {
if (!seenCR) { line++; }
column = 1;
seenCR = false;
} else if (ch === \\\"\\
\\\" || ch === \\\"\\\\u2028\\\" || ch === \\\"\\\\u2029\\\") {
line++;
column = 1;
seenCR = true;
} else {
column++;
seenCR = false;
}
}
return { line: line, column: column };
}
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e,array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++)
array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
var result = parseFunctions[startRule]();
/*
* The parser is now in one of the following three states:
*
* 1. The parser successfully parsed the whole input.
*
* - |result !== null|
* - |pos === input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 2. The parser successfully parsed only a part of the input.
*
* - |result !== null|
* - |pos < input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 3. The parser did not successfully parse any part of the input.
*
* - |result === null|
* - |pos === 0|
* - |rightmostFailuresExpected| contains at least one failure
*
* All code following this comment (including called functions) must
* handle these states.
*/
if (result === null || pos !== input.length) {
var offset = Math.max(pos, rightmostFailuresPos);
var found = offset < input.length ? input.charAt(offset) : null;
var errorPosition = computeErrorPosition();
throw new this.SyntaxError(
cleanupExpected(rightmostFailuresExpected),
found,
offset,
errorPosition.line,
errorPosition.column
);
}
return result;
},
/* Returns the parser source code. */
toSource: function() { return this._source; }
};
/* Thrown when a parser encounters a syntax error. */
result.SyntaxError = function(expected, found, offset, line, column) {
function buildMessage(expected, found) {
var expectedHumanized, foundHumanized;
switch (expected.length) {
case 0:
expectedHumanized = \\\"end of input\\\";
break;
case 1:
expectedHumanized = expected[0];
break;
default:
expectedHumanized = expected.slice(0, expected.length - 1).join(\\\", \\\")
+ \\\" or \\\"
+ expected[expected.length - 1];
}
foundHumanized = found ? quote(found) : \\\"end of input\\\";
return \\\"Expected \\\" + expectedHumanized + \\\" but \\\" + foundHumanized + \\\" found.\\\";
}
this.name = \\\"SyntaxError\\\";
this.expected = expected;
this.found = found;
this.message = buildMessage(expected, found);
this.offset = offset;
this.line = line;
this.column = column;
};
result.SyntaxError.prototype = Error.prototype;
return result;
})()\"
};
_parser._init_ = function() {
values = global.glass.values;
delete _parser._init_;
}
}).call(glass.Expression)",
"www\\js\\glass\\allTests.js": "(function() {
var global = (function() {
return this;
})();
var glass; // assigned during _init_
var glass_Expression; // assigned during _init_
var glass_JSONMergePatch; // assigned during _init_
var glass_JSONPointer; // assigned during _init_
var glass_Observable; // assigned during _init_
var glass_Component; // assigned during _init_
var allTests = this.allTests = function anonymous(callback) {
if (callback == null) {
callback = function(path, result) {
if (result == null) {
console.log(\"\\033[92mPass\\033[0m: \" + path + \"\");
} else {
console.log(\"\\033[91mFail\\033[0m: \" + path + \"\");
console.log(result.stack || result);
}
}
}
function singleTest(path, test) {
if (test == null) {
callback(path, \"test not found\");
return;
} else if (typeof test == 'object') {
for (var key in test) singleTest(path + '.' + key, test[key]);
return;
}
try {
callback(path, test());
} catch(e) {
callback(path, e);
}
}
singleTest(\"glass\", glass.test);
singleTest(\"glass.Expression\", glass_Expression.test);
singleTest(\"glass.JSONMergePatch\", glass_JSONMergePatch.test);
singleTest(\"glass.JSONPointer\", glass_JSONPointer.test);
singleTest(\"glass.Observable\", glass_Observable.test);
singleTest(\"glass.Component\", glass_Component.test);
};
allTests._init_ = function() {
glass = global.glass;
glass_Expression = global.glass.Expression;
glass_JSONMergePatch = global.glass.JSONMergePatch;
glass_JSONPointer = global.glass.JSONPointer;
glass_Observable = global.glass.Observable;
glass_Component = global.glass.Component;
delete allTests._init_;
}
allTests._init_();
glass._init_();
glass.Expression._init_();
glass.JSONMergePatch._init_();
glass.JSONPointer._init_();
glass.Observable._init_();
glass.Component._init_();
glass.Container._init_();
glass.Expression._parser._init_();
}).call(glass)",
"www/includes.html": "<script src='/js/String.js'></script>
<script src='/js/glass.js'></script>
<script src='/js/glass/Expression.js'></script>
<script src='/js/glass/JSONMergePatch.js'></script>
<script src='/js/glass/JSONPointer.js'></script>
<script src='/js/glass/Observable.js'></script>
<script src='/js/glass/Component.js'></script>
<script src='/js/glass/Container.js'></script>
<script src='/js/glass/Expression/_parser.js'></script>
<script src='/js/glass/allTests.js'></script>
",
"glass.js": "require('./www/js/String');
require('./www/js/glass');
require('./www/js/glass/Expression');
require('./www/js/glass/JSONMergePatch');
require('./www/js/glass/JSONPointer');
require('./www/js/glass/Observable');
require('./www/js/glass/Component');
require('./www/js/glass/Container');
require('./www/js/glass/Expression/_parser');
require('./www/js/glass/allTests');
"
}
} | {
options: {
input: {
dir: "runtime",
match: /\.(coffee|pegjs)$/
},
output: {
dir: "www/js"
},
script: {
includes: "www/includes.html",
prefix: "/js/"
},
module: {
main: "glass.js",
prefix: "./www/js/"
},
debug: "buildlog.html",
test: "glass.allTests",
addon: {
pregenerate: {
addUri: function(schema) {
var content, type, typeName, _ref2, _ref3;
_ref2 = schema.types;
for (typeName in _ref2) {
type = _ref2[typeName];
content = type.content;
if (content.extension) {
continue;
}
if ((_ref3 = content.uri) == null) {
content.uri = "global:/" + (content.path.replace(/\./g, '/'));
}
}
return schema;
}
}
},
namespace: ""
},
types: {
String: {
source: "extension: true
properties:
\tstartsWith: (s) -> @slice(0,s.length) is s
\tendsWith: (s) -> @slice(-s.length) is s
\tcontains: (s) -> @indexOf(s) >= 0
\ttoArray: () -> @split ''",
input: "runtime\\String.coffee",
content: {
extension: true,
properties: {
startsWith: {
value: function(s) {
return this.slice(0, s.length) === s;
},
name: "startsWith"
},
endsWith: {
value: function(s) {
return this.slice( - s.length) === s;
},
name: "endsWith"
},
contains: {
value: function(s) {
return this.indexOf(s) >= 0;
},
name: "contains"
},
toArray: {
value: function() {
return this.split('');
},
name: "toArray"
}
},
name: "String",
path: "String",
namespace: "",
require: {},
import: {},
implements: {
String: true
}
},
isFirst: true,
output: "www\\js\\String.js"
},
glass: {
source: "require:
\tString: true
# runtime type tests
isFunction: (object) -> object? and typeof object is 'function'
isString: (object) -> object?.constructor is String
isArray: (object) -> Array.isArray object
isBoolean: (object) -> object? and typeof object is 'boolean'
isNumber: (object) -> object? and typeof object is 'number'
isObject: (object) -> typeof object is 'object'
isPlainObject: (object) -> object?.constructor is Object
isPrototype: (object) -> object? and object is object.constructor.prototype
isDate: (object) -> object?.constructor is Date
isPrimitive: (object) -> isString(object) or isBoolean(object) or isNumber(object) or isDate(object)
isPrivate: (property) -> property?[0] is '_'
# generic utility functions
values: (object) -> (value for key, value of object)
# generic patch method, uses patch method built into object if present
patch: (target, pathAndPatch...) ->
patch = JSONMergePatch.create.apply null, pathAndPatch
if isFunction target?.patch
target.patch patch
else
glass.JSONMergePatch.apply target, patch
# testing assertions
_getStackLocationInfo: (e, depth) ->
line = e.stack?.split('
')[depth]
return null unless line?
match = /\\(([\\w\\W]*?):(\\d+):(\\d+)\\)/.exec line
return {
file: match[1]
line: parseInt match[2]
column: parseInt match[3]
}
_throwAssertionFailure: (message) ->
try
throw new Error \"Assertion failed: \" + message
catch e
info = _getStackLocationInfo e, 3
if info?
_dumpFile info.file, info.line - 2, info.line + 2, info.line
throw e
_dumpFile: (file, from=1, to, highlight) ->
fs = require 'fs'
return unless fs?
try
content = fs.readFileSync(file).toString()
catch e
content = \"Source not found: #{e}\"
console.log '------------------------------------------------'
console.log file
console.log '------------------------------------------------'
number = 1
if content?
lines = content.split /
|
/
to ?= lines.length
for line in lines
lineNumber = number++
if lineNumber >= from and lineNumber <= to
num = String lineNumber
while num.length < 3
num += ' '
if lineNumber is highlight
`console.log(\"\\033[91m\" + num + \": \" + line + \"\\033[0m\");`
else
`console.log(num + \": \" + line);`
console.log '------------------------------------------------'
assert: (a) ->
_throwAssertionFailure JSON.stringify(a) unless a
assertTrue: (a) ->
_throwAssertionFailure JSON.stringify(a) + \" != true\" unless a is true
assertEquals: (a, b) ->
if JSON.stringify(a) isnt JSON.stringify(b)
_throwAssertionFailure JSON.stringify(a) + ' != ' + JSON.stringify(b)
# gets a unique string identifier for any object
getId:
do: ->
counter = 0
(a) ->
if a is null
return '__null__'
if a is undefined
return '__undefined__'
if typeof a is 'object' or typeof a is 'function'
return a.id ?= '__' + (counter++) + '__'
# 12 == \"12\" under this technique
return a.toString()
getType: (path) ->
array = if isArray path then path else path.split '.'
value = global
for step in path when value?
value = value[step]
throw new Error \"Type not found: #{path}\" unless isFunction value
value
test:
values: ->
assertEquals values({a:1,b:3,c:2}), [1,3,2]
patch: ->
x = {a:{foo:1,bar:3},b:2}
patch x, 'a', 'foo', 5
assertEquals x.a.foo, 5
",
input: "runtime\\glass.coffee",
content: {
require: {
String: "String"
},
isFunction: function(object) {
return (object != null) && typeof object === 'function';
},
isString: function(object) {
return (object != null ? object.constructor: void 0) === String;
},
isArray: function(object) {
return Array.isArray(object);
},
isBoolean: function(object) {
return (object != null) && typeof object === 'boolean';
},
isNumber: function(object) {
return (object != null) && typeof object === 'number';
},
isObject: function(object) {
return typeof object === 'object';
},
isPlainObject: function(object) {
return (object != null ? object.constructor: void 0) === Object;
},
isPrototype: function(object) {
return (object != null) && object === object.constructor.prototype;
},
isDate: function(object) {
return (object != null ? object.constructor: void 0) === Date;
},
isPrimitive: function(object) {
return isString(object) || isBoolean(object) || isNumber(object) || isDate(object);
},
isPrivate: function(property) {
return (property != null ? property[0] : void 0) === '_';
},
values: function(object) {
var key, value, _results;
_results = [];
for (key in object) {
value = object[key];
_results.push(value);
}
return _results;
},
patch: function() {
var patch, pathAndPatch, target;
target = arguments[0],
pathAndPatch = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
patch = JSONMergePatch.create.apply(null, pathAndPatch);
if (isFunction(target != null ? target.patch: void 0)) {
return target.patch(patch);
} else {
return glass.JSONMergePatch.apply(target, patch);
}
},
assert: function(a) {
if (!a) {
return _throwAssertionFailure(JSON.stringify(a));
}
},
assertTrue: function(a) {
if (a !== true) {
return _throwAssertionFailure(JSON.stringify(a) + " != true");
}
},
assertEquals: function(a, b) {
if (JSON.stringify(a) !== JSON.stringify(b)) {
return _throwAssertionFailure(JSON.stringify(a) + ' != ' + JSON.stringify(b));
}
},
getId: {
do: function() {
var counter;
counter = 0;
return function(a) {
var _ref;
if (a === null) {
return '__null__';
}
if (a === void 0) {
return '__undefined__';
}
if (typeof a === 'object' || typeof a === 'function') {
return (_ref = a.id) != null ? _ref: a.id = '__' + (counter++) + '__';
}
return a.toString();
};
}
},
getType: function(path) {
var array, step, value, _i, _len;
array = isArray(path) ? path: path.split('.');
value = global;
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
if (!isFunction(value)) {
throw new Error("Type not found: " + path);
}
return value;
},
test: {
values: function() {
return assertEquals(values({
a: 1,
b: 3,
c: 2
}), [1, 3, 2]);
},
patch: function() {
var x;
x = {
a: {
foo: 1,
bar: 3
},
b: 2
};
patch(x, 'a', 'foo', 5);
return assertEquals(x.a.foo, 5);
}
},
name: "glass",
path: "glass",
namespace: "",
import: {
"glass.JSONMergePatch": "JSONMergePatch",
"glass.isFunction": "isFunction",
"glass.isString": "isString",
"glass.isArray": "isArray",
"glass.isBoolean": "isBoolean",
"glass.isNumber": "isNumber",
"glass.isDate": "isDate",
"glass.values": "values",
"glass.patch": "patch",
"glass._getStackLocationInfo": "_getStackLocationInfo",
"glass._throwAssertionFailure": "_throwAssertionFailure",
"glass._dumpFile": "_dumpFile",
"glass.assertEquals": "assertEquals"
},
uri: "global:/glass"
},
output: "www\\js\\glass.js"
},
"glass.Expression": {
source: "constructor: (op, args) ->
@op = op
@args = args if args?
@
properties:
op:
type: 'string'
args:
type: 'array'
test: ->
return
peg = require 'pegjs'
fs = require 'fs'
parserSource = fs.readFileSync 'runtime/glass/Expression/_parser.pegjs', 'utf8'
parser = peg.buildParser parserSource
tests =
\"a.b.c\": {op:\"get\",args:[{op:\"get\",args:[{op:\"ref\",args:[\"a\"]},\"b\"]},\"c\"]}
\"a.1\": {op:\"get\",args:[{op:\"ref\",args:[\"a\"]},1]}
\"true\": true
\"false\": false
\"45.8\": 45.8
\"(45.8)\": 45.8
\"((45.8))\": 45.8
\"alpha\": {op:\"ref\",args:[\"alpha\"]}
\"35 + true * 2\": {op:\"+\", args:[35, {op:\"*\", args:[true,2]}]}
\" 5 * ( 2 + 2 ) \": {op:\"*\", args:[5, {op:\"+\", args:[2,2]}]}
\" ! ! true\": {op:\"!\",args:[{op:\"!\",args:[true]}]}
\"5 + -x\": {op:\"+\",args:[5,{op:\"-\",args:[{op:\"ref\",args:[\"x\"]}]}]}
\"true == 5 >= 2\": {op:\"==\",args:[true,{op:\">=\",args:[5,2]}]}
\"1 or 2 and 3\": {op:\"or\",args:[1,{op:\"and\",args:[2,3]}]}
\"1 ? 2 : 3\": {op:\"?:\",args:[1,2,3]}
\"1 ? 2 : 3 ? 4 : 5\" : {op:\"?:\",args:[1,2,{op:\"?:\",args:[3,4,5]}]}
\"a()(1,2)\" : {op:\"call\",args:[{op:\"call\",args:[{op:\"ref\",args:[\"a\"]},[]]},[1,2]]}
\"@\" : {op:\"this\"}
\"@foo\" : {op:\"get\",args:[{op:\"this\"},\"foo\"]}
'\"hello\"': \"hello\"
'\"\\\\t\\
\\
\\\\b\\\\\\\\foo\\\\\\/\"' : \"\\t
\\b\\\\foo\\/\"
\"[]\": {op:\"array\",args:[]}
\"[1,2]\": {op:\"array\",args:[1,2]}
\"[1+2]\": {op:\"array\",args:[{op:\"+\",args:[1,2]}]}
\"{}\": {op:\"object\",args:[]}
'{\"a\":2}': {op:\"object\",args:[[\"a\",2]]}
'{\"a\":2,\"b\":1+2}': {op:\"object\",args:[[\"a\",2],[\"b\",{op:\"+\",args:[1,2]}]]}
'@\"alpha\"': {op:\"get\",args:[{op:\"this\"},\"alpha\"]}
'*': {op:\"values\",args:[]}
'*.*': {op:\"values\",args:[{op:\"values\",args:[]}]}
\"foo.*\": {op:\"values\",args:[{op:\"ref\",args:[\"foo\"]}]}
\"..\": {op:\"ancestor\",args:[1]}
\"...\": {op:\"ancestor\",args:[2]}
\"@*{1+2}\": {op:\"eval\",args:[{op:\"values\",args:[{op:\"this\"}]},{op:\"+\",args:[1,2]}]}
\"/\": {op:\"root\"}
\"/foo\": {op:\"get\",args:[{op:\"root\"},\"foo\"]}
\"/*\": {op:\"values\",args:[{op:\"root\"}]}
for text, expected of tests
result = parser.parse text
if JSON.stringify(result) is JSON.stringify(expected)
console.log 'Pass: ' + text
else
console.log text, JSON.stringify result
return
",
input: "runtime\\glass\\Expression.coffee",
content: {
constructor: function(op, args) {
this.op = op;
if (args != null) {
this.args = args;
}
return this;
},
properties: {
op: {
type: "string",
name: "op",
writable: true
},
args: {
type: "array",
name: "args",
writable: true
}
},
test: function() {
var expected, fs, parser, parserSource, peg, result, tests, text;
return;
peg = require('pegjs');
fs = require('fs');
parserSource = fs.readFileSync('runtime/glass/Expression/_parser.pegjs', 'utf8');
parser = peg.buildParser(parserSource);
tests = {
"a.b.c": {
op: "get",
args: [{
op: "get",
args: [{
op: "ref",
args: ["a"]
},
"b"]
},
"c"]
},
"a.1": {
op: "get",
args: [{
op: "ref",
args: ["a"]
},
1]
},
"true": true,
"false": false,
"45.8": 45.8,
"(45.8)": 45.8,
"((45.8))": 45.8,
"alpha": {
op: "ref",
args: ["alpha"]
},
"35 + true * 2": {
op: "+",
args: [35, {
op: "*",
args: [true, 2]
}]
},
" 5 * ( 2 + 2 ) ": {
op: "*",
args: [5, {
op: "+",
args: [2, 2]
}]
},
" ! ! true": {
op: "!",
args: [{
op: "!",
args: [true]
}]
},
"5 + -x": {
op: "+",
args: [5, {
op: "-",
args: [{
op: "ref",
args: ["x"]
}]
}]
},
"true == 5 >= 2": {
op: "==",
args: [true, {
op: ">=",
args: [5, 2]
}]
},
"1 or 2 and 3": {
op: "or",
args: [1, {
op: "and",
args: [2, 3]
}]
},
"1 ? 2 : 3": {
op: "?:",
args: [1, 2, 3]
},
"1 ? 2 : 3 ? 4 : 5": {
op: "?:",
args: [1, 2, {
op: "?:",
args: [3, 4, 5]
}]
},
"a()(1,2)": {
op: "call",
args: [{
op: "call",
args: [{
op: "ref",
args: ["a"]
},
[]]
},
[1, 2]]
},
"@": {
op: "this"
},
"@foo": {
op: "get",
args: [{
op: "this"
},
"foo"]
},
'"hello"': "hello",
'"\\t
\\b\\\\foo\\\/"': "\t
\b\\foo\/",
"[]": {
op: "array",
args: []
},
"[1,2]": {
op: "array",
args: [1, 2]
},
"[1+2]": {
op: "array",
args: [{
op: "+",
args: [1, 2]
}]
},
"{}": {
op: "object",
args: []
},
'{"a":2}': {
op: "object",
args: [["a", 2]]
},
'{"a":2,"b":1+2}': {
op: "object",
args: [["a", 2], ["b", {
op: "+",
args: [1, 2]
}]]
},
'@"alpha"': {
op: "get",
args: [{
op: "this"
},
"alpha"]
},
'*': {
op: "values",
args: []
},
'*.*': {
op: "values",
args: [{
op: "values",
args: []
}]
},
"foo.*": {
op: "values",
args: [{
op: "ref",
args: ["foo"]
}]
},
"..": {
op: "ancestor",
args: [1]
},
"...": {
op: "ancestor",
args: [2]
},
"@*{1+2}": {
op: "eval",
args: [{
op: "values",
args: [{
op: "this"
}]
},
{
op: "+",
args: [1, 2]
}]
},
"/": {
op: "root"
},
"/foo": {
op: "get",
args: [{
op: "root"
},
"foo"]
},
"/*": {
op: "values",
args: [{
op: "root"
}]
}
};
for (text in tests) {
expected = tests[text];
result = parser.parse(text);
if (JSON.stringify(result) === JSON.stringify(expected)) {
console.log('Pass: ' + text);
} else {
console.log(text, JSON.stringify(result));
}
}
},
name: "Expression",
path: "glass.Expression",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.Expression._parser": "_parser",
"glass.values": "values"
},
implements: {
"glass.Expression": true
},
uri: "global:/glass/Expression"
},
output: "www\\js\\glass\\Expression.js"
},
"glass.JSONMergePatch": {
source: "
# applies a patch to the target object and returns the resulting target
apply: (target, patch) ->
if target? and target isnt patch and isPlainObject(patch) and not isPrimitive(target)
for key, value of patch
if value is undefined
delete target[key]
else
target[key] = apply target[key], patch[key]
return target
else
return patch
# (path1, path2, path3.., patch) ->
create: ->
if arguments.length is 1
return arguments[0]
result = {}
current = result
for arg, i in arguments when i + 1 < arguments.length
last = i + 2 is arguments.length
current = current[arg] = if last then arguments[arguments.length-1] else {}
result
test: ->
assertEquals {a:{b:12}}, create 'a', 'b', 12
assertEquals {a:3}, apply({a:1,b:2}, {a:3,b:undefined})
",
input: "runtime\\glass\\JSONMergePatch.coffee",
content: {
apply: function(target, patch) {
var key, value;
if ((target != null) && target !== patch && isPlainObject(patch) && !isPrimitive(target)) {
for (key in patch) {
value = patch[key];
if (value === void 0) {
delete target[key];
} else {
target[key] = apply(target[key], patch[key]);
}
}
return target;
} else {
return patch;
}
},
create: function() {
var arg, current, i, last, result, _i, _len;
if (arguments.length === 1) {
return arguments[0];
}
result = {};
current = result;
for (i = _i = 0, _len = arguments.length; _i < _len; i = ++_i) {
arg = arguments[i];
if (! (i + 1 < arguments.length)) {
continue;
}
last = i + 2 === arguments.length;
current = current[arg] = last ? arguments[arguments.length - 1] : {};
}
return result;
},
test: function() {
assertEquals({
a: {
b: 12
}
},
create('a', 'b', 12));
return assertEquals({
a: 3
},
apply({
a: 1,
b: 2
},
{
a: 3,
b: void 0
}));
},
name: "JSONMergePatch",
path: "glass.JSONMergePatch",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONMergePatch.apply": "apply",
"glass.JSONMergePatch.create": "create",
"glass.isPlainObject": "isPlainObject",
"glass.isPrimitive": "isPrimitive",
"glass.patch": "patch",
"glass.assertEquals": "assertEquals"
},
uri: "global:/glass/JSONMergePatch"
},
output: "www\\js\\glass\\JSONMergePatch.js"
},
"glass.JSONPointer": {
source: "# json pointer implementation as per
# http://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-05
_decodeStep: (step) -> step.replace(/~1/g, '/').replace(/~0/g, '~')
_getLastStep: (pointer) ->
_decodeStep pointer.substring(pointer.lastIndexOf('/') + 1)
_getParent: (pointer) ->
if not pointer?.length
null
else
pointer.substring(0, pointer.lastIndexOf('/'))
toArray: (pointer) ->
for step in pointer.substring(1).split('/')
_decodeStep step
get: (doc, pointer) ->
value = doc
if pointer.length
path = toArray pointer
for step in path when value?
value = value[step]
value
set: (doc, pointer, value) ->
parentPointer = _getParent pointer
if parentPointer?
parent = get doc, parentPointer
lastStep = _getLastStep pointer
parent[lastStep] = value
value
test: ->
assertEquals _getParent(\"/a/b/c\"), \"/a/b\"
assertEquals _getParent(\"/a\"), \"\"
assertEquals _getParent(\"\"), null
assertEquals _getLastStep(\"/a/b/c\"), \"c\"
assertEquals _getLastStep(\"/a~0~1\"), \"a~/\"
assertEquals _getLastStep(\"\"), \"\"
# tests as per spec
doc = {
\"foo\": [\"bar\", \"baz\"],
\"\": 0,
\"a/b\": 1,
\"c%d\": 2,
\"e^f\": 3,
\"g|h\": 4,
\"i\\\\j\": 5,
\"k\\\"l\": 6,
\" \": 7,
\"m~n\": 8
}
assertEquals get(doc, \"\"), doc
assertEquals get(doc, \"/foo\"), [\"bar\", \"baz\"]
assertEquals get(doc, \"/foo/0\"), \"bar\"
assertEquals get(doc, \"/\"), 0
assertEquals get(doc, \"/a~1b\"), 1
assertEquals get(doc, \"/c%d\"), 2
assertEquals get(doc, \"/e^f\"), 3
assertEquals get(doc, \"/g|h\"), 4
assertEquals get(doc, \"/i\\\\j\"), 5
assertEquals get(doc, \"/k\\\"l\"), 6
assertEquals get(doc, \"/ \"), 7
assertEquals get(doc, \"/m~0n\"), 8
# now test set
assertEquals set(doc, \"/\", 10), 10
assertEquals doc[\"\"], 10
assertEquals set(doc, \"/foo/0\", 10), 10
assertEquals doc.foo[0], 10",
input: "runtime\\glass\\JSONPointer.coffee",
content: {
toArray: function(pointer) {
var step, _i, _len, _ref, _results;
_ref = pointer.substring(1).split('/');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
step = _ref[_i];
_results.push(_decodeStep(step));
}
return _results;
},
get: function(doc, pointer) {
var path, step, value, _i, _len;
value = doc;
if (pointer.length) {
path = toArray(pointer);
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
}
return value;
},
set: function(doc, pointer, value) {
var lastStep, parent, parentPointer;
parentPointer = _getParent(pointer);
if (parentPointer != null) {
parent = get(doc, parentPointer);
lastStep = _getLastStep(pointer);
parent[lastStep] = value;
}
return value;
},
test: function() {
var doc;
assertEquals(_getParent("/a/b/c"), "/a/b");
assertEquals(_getParent("/a"), "");
assertEquals(_getParent(""), null);
assertEquals(_getLastStep("/a/b/c"), "c");
assertEquals(_getLastStep("/a~0~1"), "a~/");
assertEquals(_getLastStep(""), "");
doc = {
"foo": ["bar", "baz"],
"": 0,
"a/b": 1,
"c%d": 2,
"e^f": 3,
"g|h": 4,
"i\\j": 5,
"k\"l": 6,
" ": 7,
"m~n": 8
};
assertEquals(get(doc, ""), doc);
assertEquals(get(doc, "/foo"), ["bar", "baz"]);
assertEquals(get(doc, "/foo/0"), "bar");
assertEquals(get(doc, "/"), 0);
assertEquals(get(doc, "/a~1b"), 1);
assertEquals(get(doc, "/c%d"), 2);
assertEquals(get(doc, "/e^f"), 3);
assertEquals(get(doc, "/g|h"), 4);
assertEquals(get(doc, "/i\\j"), 5);
assertEquals(get(doc, "/k\"l"), 6);
assertEquals(get(doc, "/ "), 7);
assertEquals(get(doc, "/m~0n"), 8);
assertEquals(set(doc, "/", 10), 10);
assertEquals(doc[""], 10);
assertEquals(set(doc, "/foo/0", 10), 10);
return assertEquals(doc.foo[0], 10);
},
name: "JSONPointer",
path: "glass.JSONPointer",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONPointer._decodeStep": "_decodeStep",
"glass.JSONPointer._getLastStep": "_getLastStep",
"glass.JSONPointer._getParent": "_getParent",
"glass.JSONPointer.toArray": "toArray",
"glass.JSONPointer.get": "get",
"glass.JSONPointer.set": "set",
"glass.assertEquals": "assertEquals"
},
uri: "global:/glass/JSONPointer"
},
output: "www\\js\\glass\\JSONPointer.js"
},
"glass.Observable": {
source: "properties:
is: (type) -> @constructor.implements[type.path ? type] is true
watchers:
serializable: false
watch: (property, watcher) ->
if isFunction property
watcher = property
property = ''
id = getId watcher
@patch 'watchers', property, id, watcher
# returns a function which will remove the watch
=> @patch 'watchers', property, getId(watcher), undefined
patch: (change) ->
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
try
JSONMergePatch.apply this, change
catch e
console.log e
finally
@notify change
return
notify: (change) ->
if @watchers?
if arguments.length > 1
change = JSONMergePatch.create.apply null, arguments
for property, watchers of @watchers
if property.length is 0 or change.hasOwnProperty property
changeArg = if property.length is 0 then change else change[property]
for id, watcher of watchers
watcher this, changeArg
return
toJSON: ->
values =
class: @constructor.path
# serialize statically defined properties
for name, property of @constructor.properties
value = @[name]
if property.serializable isnt false and not isFunction(value)
values[name] = value
# serialize custom properties if allowed by schema
if @constructor.additionalProperties isnt false
for own name, value of @ when not isPrivate name
values[name] = value
values
toString: -> @toJSON()
test:
toJSON: ->
# I need this test later
# on a class that actually has serializable properties
a = new Observable
a.x = 12
a.y = ->
a.z = true
assertEquals a, {class:'glass.Observable', x:12,z:true}
watchAll: ->
# we should actually be able to watch ourselves get added to watchers
# this is very meta.
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch watcher
# now make sure we were called with our own watcher
assert watchArgs[0] is a
assert watchArgs[1]?.watchers?[\"\"]?
# reset watchArgs, and watch something else
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assertEquals a.a, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {a:{b:3}}
# now unwatch
unwatch()
# make sure universal watcher is now empty
assertEquals a.watchers[\"\"], {}
# now reset and do a new event, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
watchProperty: ->
# watch a property
a = new Observable
watchArgs = []
watcher = (source, patch) ->
watchArgs.push source, patch
unwatch = a.watch \"foo\", watcher
# now make sure we were not called
assert watchArgs.length is 0
# reset watchArgs, and watch something else
a.patch \"foo\", \"b\", 3
assertEquals a.foo, {b:3}
assert watchArgs[0] is a
assertEquals watchArgs[1], {b:3}
# now reset and do a different property, make sure we don't see it.
watchArgs.length = 0
a.patch \"a\", \"b\", 3
assert watchArgs.length is 0
# now unwatch
unwatch()
# make sure we no longer see foo
watchArgs.length = 0
a.patch \"foo\", \"b\", 4
assert watchArgs.length is 0
",
input: "runtime\\glass\\Observable.coffee",
content: {
properties: {
is: {
value: function(type) {
var _ref;
return this.constructor["implements"][(_ref = type.path) != null ? _ref: type] === true;
},
name: "is"
},
watchers: {
serializable: false,
name: "watchers",
writable: true
},
watch: {
value: function(property, watcher) {
var id, _this = this;
if (isFunction(property)) {
watcher = property;
property = '';
}
id = getId(watcher);
this.patch('watchers', property, id, watcher);
return function() {
return _this.patch('watchers', property, getId(watcher), void 0);
};
},
name: "watch"
},
patch: {
value: function(change) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
try {
JSONMergePatch.apply(this, change);
} catch(e) {
console.log(e);
} finally {
this.notify(change);
}
},
name: "patch"
},
notify: {
value: function(change) {
var changeArg, id, property, watcher, watchers, _ref;
if (this.watchers != null) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
_ref = this.watchers;
for (property in _ref) {
watchers = _ref[property];
if (property.length === 0 || change.hasOwnProperty(property)) {
changeArg = property.length === 0 ? change: change[property];
for (id in watchers) {
watcher = watchers[id];
watcher(this, changeArg);
}
}
}
}
},
name: "notify"
},
toJSON: {
value: function() {
var name, property, value, values, _ref;
values = {
"class": this.constructor.path
};
_ref = this.constructor.properties;
for (name in _ref) {
property = _ref[name];
value = this[name];
if (property.serializable !== false && !isFunction(value)) {
values[name] = value;
}
}
if (this.constructor.additionalProperties !== false) {
for (name in this) {
if (!__hasProp.call(this, name)) continue;
value = this[name];
if (!isPrivate(name)) {
values[name] = value;
}
}
}
return values;
},
name: "toJSON"
},
toString: {
value: function() {
return this.toJSON();
},
name: "toString"
}
},
test: {
toJSON: function() {
var a;
a = new Observable;
a.x = 12;
a.y = function() {};
a.z = true;
return assertEquals(a, {
"class": 'glass.Observable',
x: 12,
z: true
});
},
watchAll: function() {
var a, unwatch, watchArgs, watcher, _ref, _ref1;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch(watcher);
assert(watchArgs[0] === a);
assert(((_ref = watchArgs[1]) != null ? (_ref1 = _ref.watchers) != null ? _ref1[""] : void 0 : void 0) != null);
watchArgs.length = 0;
a.patch("a", "b", 3);
assertEquals(a.a, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
a: {
b: 3
}
});
unwatch();
assertEquals(a.watchers[""], {});
watchArgs.length = 0;
a.patch("a", "b", 3);
return assert(watchArgs.length === 0);
},
watchProperty: function() {
var a, unwatch, watchArgs, watcher;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch("foo", watcher);
assert(watchArgs.length === 0);
a.patch("foo", "b", 3);
assertEquals(a.foo, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
b: 3
});
watchArgs.length = 0;
a.patch("a", "b", 3);
assert(watchArgs.length === 0);
unwatch();
watchArgs.length = 0;
a.patch("foo", "b", 4);
return assert(watchArgs.length === 0);
}
},
name: "Observable",
path: "glass.Observable",
namespace: "glass",
require: {
glass: "glass"
},
import: {
"glass.JSONMergePatch": "JSONMergePatch",
"glass.isFunction": "isFunction",
"glass.isPrivate": "isPrivate",
"glass.values": "values",
"glass.patch": "patch",
"glass.assert": "assert",
"glass.assertEquals": "assertEquals",
"glass.getId": "getId"
},
implements: {
"glass.Observable": true
},
uri: "global:/glass/Observable"
},
output: "www\\js\\glass\\Observable.js"
},
"glass.Component": {
source: "extends: 'Observable'
constructor: (properties) ->
@patch properties
# now site ourselves on our parent
if @parent
id = getId @
patch @parent, id, @
@
properties:
id:
description: 'string which uniquely identifies this component within its parent'
type: 'string'
parent:
description: 'the object that contains this component'
serializable: false
type: 'object'
disposed: false
dispose: -> @patch 'disposed', true
notify: (change) ->
Observable.prototype.notify.apply this, arguments
if change?.disposed
# dispose of any disposable children
for id, child of @ when child?.parent is @
child.dispose?()
# remove self from parent
if @id and @parent
patch @parent, @id, undefined
return
test:
lifecycle: ->
parent = new Component
assert not parent.id?
assert not parent.parent?
child = new Component parent:parent
# id should be automatically assigned
assert isString child.id
assert parent is child.parent
assert parent[child.id] is child
assert parent.hasOwnProperty child.id
parent.dispose()
assert child.disposed is true
assert not parent.hasOwnProperty child.id
nonEnumerability: ->
visibleKeys = (key for key of new Component)
assertEquals visibleKeys, []",
input: "runtime\\glass\\Component.coffee",
content: {
extends: ["glass.Observable"],
constructor: function(properties) {
var id;
this.patch(properties);
if (this.parent) {
id = getId(this);
patch(this.parent, id, this);
}
return this;
},
properties: {
id: {
description: "string which uniquely identifies this component within its parent",
type: "string",
name: "id",
writable: true
},
parent: {
description: "the object that contains this component",
serializable: false,
type: "object",
name: "parent",
writable: true
},
disposed: {
value: false,
name: "disposed",
writable: true
},
dispose: {
value: function() {
return this.patch('disposed', true);
},
name: "dispose"
},
notify: {
value: function(change) {
var child, id;
Observable.prototype.notify.apply(this, arguments);
if (change != null ? change.disposed: void 0) {
for (id in this) {
child = this[id];
if ((child != null ? child.parent: void 0) === this) {
if (typeof child.dispose === "function") {
child.dispose();
}
}
}
if (this.id && this.parent) {
patch(this.parent, this.id, void 0);
}
}
},
name: "notify"
}
},
test: {
lifecycle: function() {
var child, parent;
parent = new Component;
assert(!(parent.id != null));
assert(!(parent.parent != null));
child = new Component({
parent: parent
});
assert(isString(child.id));
assert(parent === child.parent);
assert(parent[child.id] === child);
assert(parent.hasOwnProperty(child.id));
parent.dispose();
assert(child.disposed === true);
return assert(!parent.hasOwnProperty(child.id));
},
nonEnumerability: function() {
var key, visibleKeys;
visibleKeys = (function() {
var _results;
_results = [];
for (key in new Component) {
_results.push(key);
}
return _results;
})();
return assertEquals(visibleKeys, []);
}
},
name: "Component",
path: "glass.Component",
namespace: "glass",
require: {
glass: "glass",
"glass.Observable": "Observable"
},
import: {
"glass.Observable": "Observable",
"glass.isString": "isString",
"glass.patch": "patch",
"glass.assert": "assert",
"glass.assertEquals": "assertEquals",
"glass.getId": "getId"
},
implements: {
"glass.Component": true,
"glass.Observable": true
},
uri: "global:/glass/Component"
},
output: "www\\js\\glass\\Component.js"
},
"glass.Container": {
source: "extends: 'Observable'
properties:
watch: ->
unwatch: ->
",
input: "runtime\\glass\\Container.coffee",
content: {
extends: ["glass.Observable"],
properties: {
watch: {
value: function() {},
name: "watch"
},
unwatch: {
value: function() {},
name: "unwatch"
}
},
name: "Container",
path: "glass.Container",
namespace: "glass",
require: {
glass: "glass",
"glass.Observable": "Observable"
},
import: {},
implements: {
"glass.Container": true,
"glass.Observable": true
},
uri: "global:/glass/Container"
},
output: "www\\js\\glass\\Container.js"
},
"glass.Expression._parser": {
source: "{
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e,array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++)
array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
}
start = expression
expression = conditional
conditional = e:or args:(\"?\" b:expression \":\" c:expression {return [b,c];})* {
while (args.length > 0) {
e = expr(\"?:\", [e].concat(args.pop()));
}
return e;
}
or = a:and b:((\"or\") and)* { return joinLeft(a,b); }
and = a:equality b:((\"and\") equality)* { return joinLeft(a,b); }
equality = a:rel b:((\"==\" / \"!=\") rel)* { return joinLeft(a,b); }
rel = a:sum b:((\"<=\" / \">=\" / \"<\" / \">\") sum)* { return joinLeft(a,b); }
sum = a:product b:((\"+\" / \"-\") product)* { return joinLeft(a,b); }
product = a:not b:((\"*\" / \"div\" / \"mod\") not)* { return joinLeft(a,b); }
not = ops:(s op:(\"!\" / \"~\" / \"+\" / \"-\") { return op; })* b:primary { return unaryRight(ops,b); }
primary = s a:(group / literal / path) s { return a; }
group = \"(\" a:expression \")\" { return a; }
literal = s a:(boolean / number / string / array / object) s { return a; }
boolean = a:(\"true\" / \"false\") { return a == \"true\"; }
number = a:([0-9]+ (\".\" [0-9]+)?) { return parseFloat(toString(a)); }
hex = [a-fA-F0-9]
// as per JSON http://www.json.org
string = a:( '\"' (
[\\u0000-\\u0021\\u0023-\\u005c\\u005e-\\uffff] // all unicode chars except \\ and \"
/ (\"\\\\\" (\"\\\"\" / \"\\\\\" / \"\\/\" / \"b\" / \"f\" / \"n\" / \"r\" / \"t\" / (\"u\" hex hex hex hex)))
)* '\"' )
{ return JSON.parse(toString(a)); }
array = \"[\" a:values \"]\" { return expr(\"array\", a); }
values = first:expression? args:(\",\" b:expression {return b;})* {
if (first != \"\") { args.unshift(first); } return args;
}
object = \"{\" a:keyvalues \"}\" { return expr(\"object\", a); }
keyvalue = s a:string s \":\" b:expression { return [a,b]; }
keyvalues = first:keyvalue? rest:(\",\" b:keyvalue {return b;})* {
if (first) { rest.unshift(first); } return rest;
}
ref = a:(\"//\" / \"/\" / \"$\" / \"**\" / \"*\" / \"..\" / \".\") b:slashProperty? {
e = expr(a); if (b) { b.args.unshift(e); e = b; } return e;
}
/ a:id { return expr(\"ref\", [a]); }
id = a:[a-z_]+ b:[a-z_0-9]* { return a.join('') + b.join(''); }
property = \"/\" a:slashProperty { return a; }
/ \"{\" a:expression \"}\" { return expr(\"{}\", [a]); } // locally scoped expression
/ \"[\" a:expression \"]\" { return expr(\"[]\", [a]); } // predicate
slashProperty = a:(id/number/string) { return expr(\"/\", [a]); }
/ a:(\"..\" / \"*\") { return expr(a, []); }
s \"space\" = [ ]* { return ''; }
path = a:root b:step* {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
}
root = a:implicitDotRoot b:dotStep? { return joinPath(a,b); }
/ explicitDotRoot
step = \".\" a:dotStep { return a; }
/ noDotStep
implicitDotRoot = \"/\" { return expr(\"root\"); }
/ \"@\" { return expr(\"this\"); }
/ \".\" a:\".\"+ { return expr(\"ancestor\", [a.length]); }
explicitDotRoot = a:id { return expr(\"ref\", [a]); }
/ \"*\" { return expr(\"values\", []); }
dotStep = a:(id / string / number) { return expr(\"get\", [a]); }
/ \"*\" { return expr(\"values\", []); }
noDotStep = \"{\" a:expression \"}\" { return expr(\"eval\", [a]); }
/ \"[\" a:expression \"]\" { return expr(\"pred\", [a]); }
/ \"(\" a:values \")\" { return expr(\"call\", [a]); }
",
input: "runtime\\glass\\Expression\\_parser.pegjs",
content: {
value: {
parse: function(input, startRule) {
var parseFunctions = {
"conditional": parse_conditional,
"or": parse_or,
"and": parse_and,
"equality": parse_equality,
"rel": parse_rel,
"sum": parse_sum,
"product": parse_product,
"not": parse_not,
"primary": parse_primary,
"group": parse_group,
"literal": parse_literal,
"boolean": parse_boolean,
"number": parse_number,
"hex": parse_hex,
"string": parse_string,
"array": parse_array,
"values": parse_values,
"object": parse_object,
"keyvalue": parse_keyvalue,
"keyvalues": parse_keyvalues,
"ref": parse_ref,
"id": parse_id,
"property": parse_property,
"slashProperty": parse_slashProperty,
"s": parse_s,
"path": parse_path,
"root": parse_root,
"step": parse_step,
"implicitDotRoot": parse_implicitDotRoot,
"explicitDotRoot": parse_explicitDotRoot,
"dotStep": parse_dotStep,
"noDotStep": parse_noDotStep
};
if (startRule !== undefined) {
if (parseFunctions[startRule] === undefined) {
throw new Error("Invalid rule name: " + quote(startRule) + ".");
}
} else {
startRule = "conditional";
}
var pos = 0;
var reportFailures = 0;
var rightmostFailuresPos = 0;
var rightmostFailuresExpected = [];
function padLeft(input, padding, length) {
var result = input;
var padLength = length - input.length;
for (var i = 0; i < padLength; i++) {
result = padding + result;
}
return result;
}
function escape(ch) {
var charCode = ch.charCodeAt(0);
var escapeChar;
var length;
if (charCode <= 0xFF) {
escapeChar = 'x';
length = 2;
} else {
escapeChar = 'u';
length = 4;
}
return '\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
}
function matchFailed(failure) {
if (pos < rightmostFailuresPos) {
return;
}
if (pos > rightmostFailuresPos) {
rightmostFailuresPos = pos;
rightmostFailuresExpected = [];
}
rightmostFailuresExpected.push(failure);
}
function parse_conditional() {
var result0, result1, result2, result3, result4, result5;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_or();
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = "?";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"?\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = ":";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, e, args) {
while (args.length > 0) {
e = expr("?:", [e].concat(args.pop()));
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_or() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_and();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "or") {
result2 = "or";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"or\"");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_and() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_equality();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 3) === "and") {
result2 = "and";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"and\"");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_equality() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_rel();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "==") {
result2 = "==";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"==\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === "!=") {
result2 = "!=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!=\"");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_rel() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_sum();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === "<=") {
result2 = "<=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<=\"");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === ">=") {
result2 = ">=";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">=\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = "<";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"<\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = ">";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\">\"");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_sum() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_product();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_product() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_not();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = "*";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "div") {
result2 = "div";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"div\"");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === "mod") {
result2 = "mod";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"mod\"");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_not() {
var result0, result1, result2;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = [];
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
while (result1 !== null) {
result0.push(result1);
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = "!";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"!\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = "~";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"~\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = "+";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"+\"");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = "-";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"-\"");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
}
if (result0 !== null) {
result1 = parse_primary();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, ops, b) {
return unaryRight(ops, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_primary() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_group();
if (result1 === null) {
result1 = parse_literal();
if (result1 === null) {
result1 = parse_path();
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_group() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_literal() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_boolean();
if (result1 === null) {
result1 = parse_number();
if (result1 === null) {
result1 = parse_string();
if (result1 === null) {
result1 = parse_array();
if (result1 === null) {
result1 = parse_object();
}
}
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_boolean() {
var result0;
var pos0;
pos0 = pos;
if (input.substr(pos, 4) === "true") {
result0 = "true";
pos += 4;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"true\"");
}
}
if (result0 === null) {
if (input.substr(pos, 5) === "false") {
result0 = "false";
pos += 5;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"false\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a == "true";
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_number() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
pos2 = pos;
if (input.charCodeAt(pos) === 46) {
result1 = ".";
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result1 !== null) {
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
if (result3 !== null) {
result2 = [];
while (result3 !== null) {
result2.push(result3);
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[0-9]");
}
}
}
} else {
result2 = null;
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos2;
}
} else {
result1 = null;
pos = pos2;
}
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return parseFloat(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_hex() {
var result0;
if (/^[a-fA-F0-9]/.test(input.charAt(pos))) {
result0 = input.charAt(pos);
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("[a-fA-F0-9]");
}
}
return result0;
}
function parse_string() {
var result0, result1, result2, result3, result4, result5, result6, result7;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 34) {
result0 = "\"";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result0 !== null) {
result1 = [];
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[\0-!#-\\^-\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[\\0-!#-\\\\^-\\uFFFF]");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = "\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = "\"";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = "\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"\\\\\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = "/";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = "b";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"b\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = "f";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"f\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = "n";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"n\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = "r";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"r\"");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = "t";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"t\"");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = "u";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\"u\"");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
}
if (result1 !== null) {
if (input.charCodeAt(pos) === 34) {
result2 = "\"";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"\\\"\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return JSON.parse(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_array() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("array", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_values() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_conditional();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, args) {
if (first != "") {
args.unshift(first);
}
return args;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_object() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_keyvalues();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("object", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalue() {
var result0, result1, result2, result3, result4;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_string();
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
if (input.charCodeAt(pos) === 58) {
result3 = ":";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("\":\"");
}
}
if (result3 !== null) {
result4 = parse_conditional();
if (result4 !== null) {
result0 = [result0, result1, result2, result3, result4];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return [a, b];
})(pos0, result0[1], result0[4]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalues() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_keyvalue();
result0 = result0 !== null ? result0: "";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = ",";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\",\"");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, rest) {
if (first) {
rest.unshift(first);
}
return rest;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_ref() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.substr(pos, 2) === "//") {
result0 = "//";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"//\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 36) {
result0 = "$";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"$\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "**") {
result0 = "**";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"**\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
}
}
}
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
e = expr(a);
if (b) {
b.args.unshift(e);
e = b;
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_id() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[a-z_]");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
result1 = [];
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("[a-z_0-9]");
}
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return a.join('') + b.join('');
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_property() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("{}", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("[]", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_slashProperty() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_number();
if (result0 === null) {
result0 = parse_string();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("/", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.substr(pos, 2) === "..") {
result0 = "..";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"..\"");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(a, []);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_s() {
var result0, result1;
var pos0;
reportFailures++;
pos0 = pos;
result0 = [];
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
while (result1 !== null) {
result0.push(result1);
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("[ ]");
}
}
}
if (result0 !== null) {
result0 = (function(offset) {
return '';
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
reportFailures--;
if (reportFailures === 0 && result0 === null) {
matchFailed("space");
}
return result0;
}
function parse_path() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_root();
if (result0 !== null) {
result1 = [];
result2 = parse_step();
while (result2 !== null) {
result1.push(result2);
result2 = parse_step();
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_root() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_implicitDotRoot();
if (result0 !== null) {
result1 = parse_dotStep();
result1 = result1 !== null ? result1: "";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinPath(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_explicitDotRoot();
}
return result0;
}
function parse_step() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
result1 = parse_dotStep();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_noDotStep();
}
return result0;
}
function parse_implicitDotRoot() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = "/";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"/\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("root");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 64) {
result0 = "@";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"@\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("this");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = ".";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result0 !== null) {
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
if (result2 !== null) {
result1 = [];
while (result2 !== null) {
result1.push(result2);
if (input.charCodeAt(pos) === 46) {
result2 = ".";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\".\"");
}
}
}
} else {
result1 = null;
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ancestor", [a.length]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_explicitDotRoot() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("ref", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_dotStep() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_string();
if (result0 === null) {
result0 = parse_number();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("get", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = "*";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"*\"");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr("values", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_noDotStep() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = "{";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"{\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = "}";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"}\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("eval", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = "[";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"[\"");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = "]";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\"]\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("pred", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = "(";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed("\"(\"");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = ")";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed("\")\"");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr("call", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function cleanupExpected(expected) {
expected.sort();
var lastExpected = null;
var cleanExpected = [];
for (var i = 0; i < expected.length; i++) {
if (expected[i] !== lastExpected) {
cleanExpected.push(expected[i]);
lastExpected = expected[i];
}
}
return cleanExpected;
}
function computeErrorPosition() {
/*
* The first idea was to use |String.split| to break the input up to the
* error position along newlines and derive the line and column from
* there. However IE's |split| implementation is so broken that it was
* enough to prevent it.
*/
var line = 1;
var column = 1;
var seenCR = false;
for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
var ch = input.charAt(i);
if (ch === "
") {
if (!seenCR) {
line++;
}
column = 1;
seenCR = false;
} else if (ch === "
" || ch === "\u2028" || ch === "\u2029") {
line++;
column = 1;
seenCR = true;
} else {
column++;
seenCR = false;
}
}
return {
line: line,
column: column
};
}
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e, array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++) array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
var result = parseFunctions[startRule]();
/*
* The parser is now in one of the following three states:
*
* 1. The parser successfully parsed the whole input.
*
* - |result !== null|
* - |pos === input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 2. The parser successfully parsed only a part of the input.
*
* - |result !== null|
* - |pos < input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 3. The parser did not successfully parse any part of the input.
*
* - |result === null|
* - |pos === 0|
* - |rightmostFailuresExpected| contains at least one failure
*
* All code following this comment (including called functions) must
* handle these states.
*/
if (result === null || pos !== input.length) {
var offset = Math.max(pos, rightmostFailuresPos);
var found = offset < input.length ? input.charAt(offset) : null;
var errorPosition = computeErrorPosition();
throw new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column);
}
return result;
},
toSource: function() {
return this._source;
},
SyntaxError: function(expected, found, offset, line, column) {
function buildMessage(expected, found) {
var expectedHumanized, foundHumanized;
switch (expected.length) {
case 0:
expectedHumanized = "end of input";
break;
case 1:
expectedHumanized = expected[0];
break;
default:
expectedHumanized = expected.slice(0, expected.length - 1).join(", ") + " or " + expected[expected.length - 1];
}
foundHumanized = found ? quote(found) : "end of input";
return "Expected " + expectedHumanized + " but " + foundHumanized + " found.";
}
this.name = "SyntaxError";
this.expected = expected;
this.found = found;
this.message = buildMessage(expected, found);
this.offset = offset;
this.line = line;
this.column = column;
}
},
name: "_parser",
path: "glass.Expression._parser",
namespace: "glass.Expression",
require: {
"glass.Expression": "Expression"
},
import: {
"glass.values": "values"
},
uri: "global:/glass/Expression/_parser"
},
output: "www\\js\\glass\\Expression\\_parser.js"
},
"glass.allTests": {
content: {
path: "glass.allTests",
name: "allTests",
namespace: "glass",
import: {
glass: "glass",
"glass.Expression": "glass_Expression",
"glass.JSONMergePatch": "glass_JSONMergePatch",
"glass.JSONPointer": "glass_JSONPointer",
"glass.Observable": "glass_Observable",
"glass.Component": "glass_Component"
},
value: function anonymous(callback) {
if (callback == null) {
callback = function(path, result) {
if (result == null) {
console.log("\033[92mPass\033[0m: " + path + "");
} else {
console.log("\033[91mFail\033[0m: " + path + "");
console.log(result.stack || result);
}
}
}
function singleTest(path, test) {
if (test == null) {
callback(path, "test not found");
return;
} else if (typeof test == 'object') {
for (var key in test) singleTest(path + '.' + key, test[key]);
return;
}
try {
callback(path, test());
} catch(e) {
callback(path, e);
}
}
singleTest("glass", glass.test);
singleTest("glass.Expression", glass_Expression.test);
singleTest("glass.JSONMergePatch", glass_JSONMergePatch.test);
singleTest("glass.JSONPointer", glass_JSONPointer.test);
singleTest("glass.Observable", glass_Observable.test);
singleTest("glass.Component", glass_Component.test);
}
},
isLast: true,
output: "www\\js\\glass\\allTests.js"
}
},
output: {
"www\\js\\String.js": "(function() {
var global = (function() {
return this;
})();
if (String.prototype.startsWith == null) {
Object.defineProperty(String.prototype, \"startsWith\", {
value: function(s) {
return this.slice(0, s.length) === s;
},
name: \"startsWith\"
});
}
if (String.prototype.endsWith == null) {
Object.defineProperty(String.prototype, \"endsWith\", {
value: function(s) {
return this.slice( - s.length) === s;
},
name: \"endsWith\"
});
}
if (String.prototype.contains == null) {
Object.defineProperty(String.prototype, \"contains\", {
value: function(s) {
return this.indexOf(s) >= 0;
},
name: \"contains\"
});
}
if (String.prototype.toArray == null) {
Object.defineProperty(String.prototype, \"toArray\", {
value: function() {
return this.split('');
},
name: \"toArray\"
});
}
String._init_ = function() {
delete String._init_;
}
}).call()",
"www\\js\\glass.js": "(function() {
var global = (function() {
return this;
})();
var JSONMergePatch; // assigned during _init_
var isFunction; // assigned during _init_
var isString; // assigned during _init_
var isArray; // assigned during _init_
var isBoolean; // assigned during _init_
var isNumber; // assigned during _init_
var isDate; // assigned during _init_
var values; // assigned during _init_
var patch; // assigned during _init_
var _getStackLocationInfo; // assigned during _init_
var _throwAssertionFailure; // assigned during _init_
var _dumpFile; // assigned during _init_
var assertEquals; // assigned during _init_
var glass = this.glass = {
isFunction: function(object) {
return (object != null) && typeof object === 'function';
},
isString: function(object) {
return (object != null ? object.constructor: void 0) === String;
},
isArray: function(object) {
return Array.isArray(object);
},
isBoolean: function(object) {
return (object != null) && typeof object === 'boolean';
},
isNumber: function(object) {
return (object != null) && typeof object === 'number';
},
isObject: function(object) {
return typeof object === 'object';
},
isPlainObject: function(object) {
return (object != null ? object.constructor: void 0) === Object;
},
isPrototype: function(object) {
return (object != null) && object === object.constructor.prototype;
},
isDate: function(object) {
return (object != null ? object.constructor: void 0) === Date;
},
isPrimitive: function(object) {
return isString(object) || isBoolean(object) || isNumber(object) || isDate(object);
},
isPrivate: function(property) {
return (property != null ? property[0] : void 0) === '_';
},
values: function(object) {
var key, value, _results;
_results = [];
for (key in object) {
value = object[key];
_results.push(value);
}
return _results;
},
patch: function() {
var patch, pathAndPatch, target;
target = arguments[0],
pathAndPatch = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
patch = JSONMergePatch.create.apply(null, pathAndPatch);
if (isFunction(target != null ? target.patch: void 0)) {
return target.patch(patch);
} else {
return glass.JSONMergePatch.apply(target, patch);
}
},
_getStackLocationInfo: function(e, depth) {
var line, match, _ref;
line = (_ref = e.stack) != null ? _ref.split('
')[depth] : void 0;
if (line == null) {
return null;
}
match = /\\(([\\w\\W]*?):(\\d+):(\\d+)\\)/.exec(line);
return {
file: match[1],
line: parseInt(match[2]),
column: parseInt(match[3])
};
},
_throwAssertionFailure: function(message) {
var info;
try {
throw new Error(\"Assertion failed: \" + message);
} catch(e) {
info = _getStackLocationInfo(e, 3);
if (info != null) {
_dumpFile(info.file, info.line - 2, info.line + 2, info.line);
}
throw e;
}
},
_dumpFile: function(file, from, to, highlight) {
var content, fs, line, lineNumber, lines, num, number, _i, _len;
if (from == null) {
from = 1;
}
fs = require('fs');
if (fs == null) {
return;
}
try {
content = fs.readFileSync(file).toString();
} catch(e) {
content = \"Source not found: \" + e;
}
console.log('------------------------------------------------');
console.log(file);
console.log('------------------------------------------------');
number = 1;
if (content != null) {
lines = content.split(/
|
/);
if (to == null) {
to = lines.length;
}
for (_i = 0, _len = lines.length; _i < _len; _i++) {
line = lines[_i];
lineNumber = number++;
if (lineNumber >= from && lineNumber <= to) {
num = String(lineNumber);
while (num.length < 3) {
num += ' ';
}
if (lineNumber === highlight) {
console.log(\"\\033[91m\" + num + \": \" + line + \"\\033[0m\");;
} else {
console.log(num + \": \" + line);;
}
}
}
}
return console.log('------------------------------------------------');
},
assert: function(a) {
if (!a) {
return _throwAssertionFailure(JSON.stringify(a));
}
},
assertTrue: function(a) {
if (a !== true) {
return _throwAssertionFailure(JSON.stringify(a) + \" != true\");
}
},
assertEquals: function(a, b) {
if (JSON.stringify(a) !== JSON.stringify(b)) {
return _throwAssertionFailure(JSON.stringify(a) + ' != ' + JSON.stringify(b));
}
},
getId: (function() {
var counter;
counter = 0;
return function(a) {
var _ref;
if (a === null) {
return '__null__';
}
if (a === void 0) {
return '__undefined__';
}
if (typeof a === 'object' || typeof a === 'function') {
return (_ref = a.id) != null ? _ref: a.id = '__' + (counter++) + '__';
}
return a.toString();
};
})(),
getType: function(path) {
var array, step, value, _i, _len;
array = isArray(path) ? path: path.split('.');
value = global;
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
if (!isFunction(value)) {
throw new Error(\"Type not found: \" + path);
}
return value;
},
test: {
values: function() {
return assertEquals(values({
a: 1,
b: 3,
c: 2
}), [1, 3, 2]);
},
patch: function() {
var x;
x = {
a: {
foo: 1,
bar: 3
},
b: 2
};
patch(x, 'a', 'foo', 5);
return assertEquals(x.a.foo, 5);
}
},
path: \"glass\",
uri: \"global:/glass\"
};
glass._init_ = function() {
JSONMergePatch = global.glass.JSONMergePatch;
isFunction = global.glass.isFunction;
isString = global.glass.isString;
isArray = global.glass.isArray;
isBoolean = global.glass.isBoolean;
isNumber = global.glass.isNumber;
isDate = global.glass.isDate;
values = global.glass.values;
patch = global.glass.patch;
_getStackLocationInfo = global.glass._getStackLocationInfo;
_throwAssertionFailure = global.glass._throwAssertionFailure;
_dumpFile = global.glass._dumpFile;
assertEquals = global.glass.assertEquals;
delete glass._init_;
}
}).call()",
"www\\js\\glass\\Expression.js": "(function() {
var global = (function() {
return this;
})();
var glass = this;
var _parser; // assigned during _init_
var values; // assigned during _init_
var Expression = this.Expression = function Expression(op, args) {
this.op = op;
if (args != null) {
this.args = args;
}
return this;
};
Expression.properties = {
op: {
type: \"string\",
name: \"op\",
writable: true
},
args: {
type: \"array\",
name: \"args\",
writable: true
}
};
Expression.test = function() {
var expected, fs, parser, parserSource, peg, result, tests, text;
return;
peg = require('pegjs');
fs = require('fs');
parserSource = fs.readFileSync('runtime/glass/Expression/_parser.pegjs', 'utf8');
parser = peg.buildParser(parserSource);
tests = {
\"a.b.c\": {
op: \"get\",
args: [{
op: \"get\",
args: [{
op: \"ref\",
args: [\"a\"]
},
\"b\"]
},
\"c\"]
},
\"a.1\": {
op: \"get\",
args: [{
op: \"ref\",
args: [\"a\"]
},
1]
},
\"true\": true,
\"false\": false,
\"45.8\": 45.8,
\"(45.8)\": 45.8,
\"((45.8))\": 45.8,
\"alpha\": {
op: \"ref\",
args: [\"alpha\"]
},
\"35 + true * 2\": {
op: \"+\",
args: [35, {
op: \"*\",
args: [true, 2]
}]
},
\" 5 * ( 2 + 2 ) \": {
op: \"*\",
args: [5, {
op: \"+\",
args: [2, 2]
}]
},
\" ! ! true\": {
op: \"!\",
args: [{
op: \"!\",
args: [true]
}]
},
\"5 + -x\": {
op: \"+\",
args: [5, {
op: \"-\",
args: [{
op: \"ref\",
args: [\"x\"]
}]
}]
},
\"true == 5 >= 2\": {
op: \"==\",
args: [true, {
op: \">=\",
args: [5, 2]
}]
},
\"1 or 2 and 3\": {
op: \"or\",
args: [1, {
op: \"and\",
args: [2, 3]
}]
},
\"1 ? 2 : 3\": {
op: \"?:\",
args: [1, 2, 3]
},
\"1 ? 2 : 3 ? 4 : 5\": {
op: \"?:\",
args: [1, 2, {
op: \"?:\",
args: [3, 4, 5]
}]
},
\"a()(1,2)\": {
op: \"call\",
args: [{
op: \"call\",
args: [{
op: \"ref\",
args: [\"a\"]
},
[]]
},
[1, 2]]
},
\"@\": {
op: \"this\"
},
\"@foo\": {
op: \"get\",
args: [{
op: \"this\"
},
\"foo\"]
},
'\"hello\"': \"hello\",
'\"\\\\t\\
\\
\\\\b\\\\\\\\foo\\\\\\/\"': \"\\t
\\b\\\\foo\\/\",
\"[]\": {
op: \"array\",
args: []
},
\"[1,2]\": {
op: \"array\",
args: [1, 2]
},
\"[1+2]\": {
op: \"array\",
args: [{
op: \"+\",
args: [1, 2]
}]
},
\"{}\": {
op: \"object\",
args: []
},
'{\"a\":2}': {
op: \"object\",
args: [[\"a\", 2]]
},
'{\"a\":2,\"b\":1+2}': {
op: \"object\",
args: [[\"a\", 2], [\"b\", {
op: \"+\",
args: [1, 2]
}]]
},
'@\"alpha\"': {
op: \"get\",
args: [{
op: \"this\"
},
\"alpha\"]
},
'*': {
op: \"values\",
args: []
},
'*.*': {
op: \"values\",
args: [{
op: \"values\",
args: []
}]
},
\"foo.*\": {
op: \"values\",
args: [{
op: \"ref\",
args: [\"foo\"]
}]
},
\"..\": {
op: \"ancestor\",
args: [1]
},
\"...\": {
op: \"ancestor\",
args: [2]
},
\"@*{1+2}\": {
op: \"eval\",
args: [{
op: \"values\",
args: [{
op: \"this\"
}]
},
{
op: \"+\",
args: [1, 2]
}]
},
\"/\": {
op: \"root\"
},
\"/foo\": {
op: \"get\",
args: [{
op: \"root\"
},
\"foo\"]
},
\"/*\": {
op: \"values\",
args: [{
op: \"root\"
}]
}
};
for (text in tests) {
expected = tests[text];
result = parser.parse(text);
if (JSON.stringify(result) === JSON.stringify(expected)) {
console.log('Pass: ' + text);
} else {
console.log(text, JSON.stringify(result));
}
}
};
Expression.path = \"glass.Expression\";
Expression.implements = {
\"glass.Expression\": true
};
Expression.uri = \"global:/glass/Expression\";
Object.defineProperties(Expression.prototype, Expression.properties);
Expression._init_ = function() {
_parser = global.glass.Expression._parser;
values = global.glass.values;
delete Expression._init_;
}
}).call(glass)",
"www\\js\\glass\\JSONMergePatch.js": "(function() {
var global = (function() {
return this;
})();
var glass = this;
var apply; // assigned during _init_
var create; // assigned during _init_
var isPlainObject; // assigned during _init_
var isPrimitive; // assigned during _init_
var patch; // assigned during _init_
var assertEquals; // assigned during _init_
var JSONMergePatch = this.JSONMergePatch = {
apply: function(target, patch) {
var key, value;
if ((target != null) && target !== patch && isPlainObject(patch) && !isPrimitive(target)) {
for (key in patch) {
value = patch[key];
if (value === void 0) {
delete target[key];
} else {
target[key] = apply(target[key], patch[key]);
}
}
return target;
} else {
return patch;
}
},
create: function() {
var arg, current, i, last, result, _i, _len;
if (arguments.length === 1) {
return arguments[0];
}
result = {};
current = result;
for (i = _i = 0, _len = arguments.length; _i < _len; i = ++_i) {
arg = arguments[i];
if (! (i + 1 < arguments.length)) {
continue;
}
last = i + 2 === arguments.length;
current = current[arg] = last ? arguments[arguments.length - 1] : {};
}
return result;
},
test: function() {
assertEquals({
a: {
b: 12
}
},
create('a', 'b', 12));
return assertEquals({
a: 3
},
apply({
a: 1,
b: 2
},
{
a: 3,
b: void 0
}));
},
path: \"glass.JSONMergePatch\",
uri: \"global:/glass/JSONMergePatch\"
};
JSONMergePatch._init_ = function() {
apply = global.glass.JSONMergePatch.apply;
create = global.glass.JSONMergePatch.create;
isPlainObject = global.glass.isPlainObject;
isPrimitive = global.glass.isPrimitive;
patch = global.glass.patch;
assertEquals = global.glass.assertEquals;
delete JSONMergePatch._init_;
}
}).call(glass)",
"www\\js\\glass\\JSONPointer.js": "(function() {
var global = (function() {
return this;
})();
var glass = this;
var _decodeStep; // assigned during _init_
var _getLastStep; // assigned during _init_
var _getParent; // assigned during _init_
var toArray; // assigned during _init_
var get; // assigned during _init_
var set; // assigned during _init_
var assertEquals; // assigned during _init_
var JSONPointer = this.JSONPointer = {
_decodeStep: function(step) {
return step.replace(/~1/g, '/').replace(/~0/g, '~');
},
_getLastStep: function(pointer) {
return _decodeStep(pointer.substring(pointer.lastIndexOf('/') + 1));
},
_getParent: function(pointer) {
if (! (pointer != null ? pointer.length: void 0)) {
return null;
} else {
return pointer.substring(0, pointer.lastIndexOf('/'));
}
},
toArray: function(pointer) {
var step, _i, _len, _ref, _results;
_ref = pointer.substring(1).split('/');
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
step = _ref[_i];
_results.push(_decodeStep(step));
}
return _results;
},
get: function(doc, pointer) {
var path, step, value, _i, _len;
value = doc;
if (pointer.length) {
path = toArray(pointer);
for (_i = 0, _len = path.length; _i < _len; _i++) {
step = path[_i];
if (value != null) {
value = value[step];
}
}
}
return value;
},
set: function(doc, pointer, value) {
var lastStep, parent, parentPointer;
parentPointer = _getParent(pointer);
if (parentPointer != null) {
parent = get(doc, parentPointer);
lastStep = _getLastStep(pointer);
parent[lastStep] = value;
}
return value;
},
test: function() {
var doc;
assertEquals(_getParent(\"/a/b/c\"), \"/a/b\");
assertEquals(_getParent(\"/a\"), \"\");
assertEquals(_getParent(\"\"), null);
assertEquals(_getLastStep(\"/a/b/c\"), \"c\");
assertEquals(_getLastStep(\"/a~0~1\"), \"a~/\");
assertEquals(_getLastStep(\"\"), \"\");
doc = {
\"foo\": [\"bar\", \"baz\"],
\"\": 0,
\"a/b\": 1,
\"c%d\": 2,
\"e^f\": 3,
\"g|h\": 4,
\"i\\\\j\": 5,
\"k\\\"l\": 6,
\" \": 7,
\"m~n\": 8
};
assertEquals(get(doc, \"\"), doc);
assertEquals(get(doc, \"/foo\"), [\"bar\", \"baz\"]);
assertEquals(get(doc, \"/foo/0\"), \"bar\");
assertEquals(get(doc, \"/\"), 0);
assertEquals(get(doc, \"/a~1b\"), 1);
assertEquals(get(doc, \"/c%d\"), 2);
assertEquals(get(doc, \"/e^f\"), 3);
assertEquals(get(doc, \"/g|h\"), 4);
assertEquals(get(doc, \"/i\\\\j\"), 5);
assertEquals(get(doc, \"/k\\\"l\"), 6);
assertEquals(get(doc, \"/ \"), 7);
assertEquals(get(doc, \"/m~0n\"), 8);
assertEquals(set(doc, \"/\", 10), 10);
assertEquals(doc[\"\"], 10);
assertEquals(set(doc, \"/foo/0\", 10), 10);
return assertEquals(doc.foo[0], 10);
},
path: \"glass.JSONPointer\",
uri: \"global:/glass/JSONPointer\"
};
JSONPointer._init_ = function() {
_decodeStep = global.glass.JSONPointer._decodeStep;
_getLastStep = global.glass.JSONPointer._getLastStep;
_getParent = global.glass.JSONPointer._getParent;
toArray = global.glass.JSONPointer.toArray;
get = global.glass.JSONPointer.get;
set = global.glass.JSONPointer.set;
assertEquals = global.glass.assertEquals;
delete JSONPointer._init_;
}
}).call(glass)",
"www\\js\\glass\\Observable.js": "(function() {
var global = (function() {
return this;
})();
var glass = this;
var JSONMergePatch; // assigned during _init_
var isFunction; // assigned during _init_
var isPrivate; // assigned during _init_
var values; // assigned during _init_
var patch; // assigned during _init_
var assert; // assigned during _init_
var assertEquals; // assigned during _init_
var getId; // assigned during _init_
var Observable = this.Observable = function Observable(properties) {
var key;
if (properties != null) {
for (key in properties) {
this[key] = properties[key];
}
}
}
Observable.properties = {
is: {
value: function(type) {
var _ref;
return this.constructor[\"implements\"][(_ref = type.path) != null ? _ref: type] === true;
},
name: \"is\"
},
watchers: {
serializable: false,
name: \"watchers\",
writable: true
},
watch: {
value: function(property, watcher) {
var id, _this = this;
if (isFunction(property)) {
watcher = property;
property = '';
}
id = getId(watcher);
this.patch('watchers', property, id, watcher);
return function() {
return _this.patch('watchers', property, getId(watcher), void 0);
};
},
name: \"watch\"
},
patch: {
value: function(change) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
try {
JSONMergePatch.apply(this, change);
} catch(e) {
console.log(e);
} finally {
this.notify(change);
}
},
name: \"patch\"
},
notify: {
value: function(change) {
var changeArg, id, property, watcher, watchers, _ref;
if (this.watchers != null) {
if (arguments.length > 1) {
change = JSONMergePatch.create.apply(null, arguments);
}
_ref = this.watchers;
for (property in _ref) {
watchers = _ref[property];
if (property.length === 0 || change.hasOwnProperty(property)) {
changeArg = property.length === 0 ? change: change[property];
for (id in watchers) {
watcher = watchers[id];
watcher(this, changeArg);
}
}
}
}
},
name: \"notify\"
},
toJSON: {
value: function() {
var name, property, value, values, _ref;
values = {
\"class\": this.constructor.path
};
_ref = this.constructor.properties;
for (name in _ref) {
property = _ref[name];
value = this[name];
if (property.serializable !== false && !isFunction(value)) {
values[name] = value;
}
}
if (this.constructor.additionalProperties !== false) {
for (name in this) {
if (!__hasProp.call(this, name)) continue;
value = this[name];
if (!isPrivate(name)) {
values[name] = value;
}
}
}
return values;
},
name: \"toJSON\"
},
toString: {
value: function() {
return this.toJSON();
},
name: \"toString\"
}
};
Observable.test = {
toJSON: function() {
var a;
a = new Observable;
a.x = 12;
a.y = function() {};
a.z = true;
return assertEquals(a, {
\"class\": 'glass.Observable',
x: 12,
z: true
});
},
watchAll: function() {
var a, unwatch, watchArgs, watcher, _ref, _ref1;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch(watcher);
assert(watchArgs[0] === a);
assert(((_ref = watchArgs[1]) != null ? (_ref1 = _ref.watchers) != null ? _ref1[\"\"] : void 0 : void 0) != null);
watchArgs.length = 0;
a.patch(\"a\", \"b\", 3);
assertEquals(a.a, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
a: {
b: 3
}
});
unwatch();
assertEquals(a.watchers[\"\"], {});
watchArgs.length = 0;
a.patch(\"a\", \"b\", 3);
return assert(watchArgs.length === 0);
},
watchProperty: function() {
var a, unwatch, watchArgs, watcher;
a = new Observable;
watchArgs = [];
watcher = function(source, patch) {
return watchArgs.push(source, patch);
};
unwatch = a.watch(\"foo\", watcher);
assert(watchArgs.length === 0);
a.patch(\"foo\", \"b\", 3);
assertEquals(a.foo, {
b: 3
});
assert(watchArgs[0] === a);
assertEquals(watchArgs[1], {
b: 3
});
watchArgs.length = 0;
a.patch(\"a\", \"b\", 3);
assert(watchArgs.length === 0);
unwatch();
watchArgs.length = 0;
a.patch(\"foo\", \"b\", 4);
return assert(watchArgs.length === 0);
}
};
Observable.path = \"glass.Observable\";
Observable.implements = {
\"glass.Observable\": true
};
Observable.uri = \"global:/glass/Observable\";
Object.defineProperties(Observable.prototype, Observable.properties);
Observable._init_ = function() {
JSONMergePatch = global.glass.JSONMergePatch;
isFunction = global.glass.isFunction;
isPrivate = global.glass.isPrivate;
values = global.glass.values;
patch = global.glass.patch;
assert = global.glass.assert;
assertEquals = global.glass.assertEquals;
getId = global.glass.getId;
delete Observable._init_;
}
}).call(glass)",
"www\\js\\glass\\Component.js": "(function() {
var global = (function() {
return this;
})();
var glass = this;
var Observable = global.glass.Observable;
var Observable; // assigned during _init_
var isString; // assigned during _init_
var patch; // assigned during _init_
var assert; // assigned during _init_
var assertEquals; // assigned during _init_
var getId; // assigned during _init_
var Component = this.Component = function Component(properties) {
var id;
this.patch(properties);
if (this.parent) {
id = getId(this);
patch(this.parent, id, this);
}
return this;
};
Component.properties = {
id: {
description: \"string which uniquely identifies this component within its parent\",
type: \"string\",
name: \"id\",
writable: true
},
parent: {
description: \"the object that contains this component\",
serializable: false,
type: \"object\",
name: \"parent\",
writable: true
},
disposed: {
value: false,
name: \"disposed\",
writable: true
},
dispose: {
value: function() {
return this.patch('disposed', true);
},
name: \"dispose\"
},
notify: {
value: function(change) {
var child, id;
Observable.prototype.notify.apply(this, arguments);
if (change != null ? change.disposed: void 0) {
for (id in this) {
child = this[id];
if ((child != null ? child.parent: void 0) === this) {
if (typeof child.dispose === \"function\") {
child.dispose();
}
}
}
if (this.id && this.parent) {
patch(this.parent, this.id, void 0);
}
}
},
name: \"notify\"
}
};
Component.test = {
lifecycle: function() {
var child, parent;
parent = new Component;
assert(!(parent.id != null));
assert(!(parent.parent != null));
child = new Component({
parent: parent
});
assert(isString(child.id));
assert(parent === child.parent);
assert(parent[child.id] === child);
assert(parent.hasOwnProperty(child.id));
parent.dispose();
assert(child.disposed === true);
return assert(!parent.hasOwnProperty(child.id));
},
nonEnumerability: function() {
var key, visibleKeys;
visibleKeys = (function() {
var _results;
_results = [];
for (key in new Component) {
_results.push(key);
}
return _results;
})();
return assertEquals(visibleKeys, []);
}
};
Component.path = \"glass.Component\";
Component.implements = {
\"glass.Component\": true,
\"glass.Observable\": true
};
Component.uri = \"global:/glass/Component\";
(function() {
var baseTypes = [Observable];
var i, j, baseType, a, b;
for (i = 0; i < baseTypes.length; i++) {
baseType = baseTypes[i];
for (key in baseType.properties) {
a = Component.properties[key];
b = baseType.properties[key];
if (a != null && b != null && a.constructor === Object && b.constructor === Object) {
for (j in b) {
if (!a.hasOwnProperty(j)) a[j] = b[j];
}
} else if (!Component.properties.hasOwnProperty(key)) {
Component.properties[key] = b;
}
}
}
})();
Object.defineProperties(Component.prototype, Component.properties);
Component._init_ = function() {
Observable = global.glass.Observable;
isString = global.glass.isString;
patch = global.glass.patch;
assert = global.glass.assert;
assertEquals = global.glass.assertEquals;
getId = global.glass.getId;
delete Component._init_;
}
}).call(glass)",
"www\\js\\glass\\Container.js": "(function() {
var global = (function() {
return this;
})();
var glass = this;
var Observable = global.glass.Observable;
var Container = this.Container = function Container(properties) {
var key;
if (properties != null) {
for (key in properties) {
this[key] = properties[key];
}
}
}
Container.properties = {
watch: {
value: function() {},
name: \"watch\"
},
unwatch: {
value: function() {},
name: \"unwatch\"
}
};
Container.path = \"glass.Container\";
Container.implements = {
\"glass.Container\": true,
\"glass.Observable\": true
};
Container.uri = \"global:/glass/Container\";
(function() {
var baseTypes = [Observable];
var i, j, baseType, a, b;
for (i = 0; i < baseTypes.length; i++) {
baseType = baseTypes[i];
for (key in baseType.properties) {
a = Container.properties[key];
b = baseType.properties[key];
if (a != null && b != null && a.constructor === Object && b.constructor === Object) {
for (j in b) {
if (!a.hasOwnProperty(j)) a[j] = b[j];
}
} else if (!Container.properties.hasOwnProperty(key)) {
Container.properties[key] = b;
}
}
}
})();
Object.defineProperties(Container.prototype, Container.properties);
Container._init_ = function() {
delete Container._init_;
}
}).call(glass)",
"www\\js\\glass\\Expression\\_parser.js": "(function() {
var global = (function() {
return this;
})();
var Expression = this;
var values; // assigned during _init_
var _parser = this._parser = {
parse: function(input, startRule) {
var parseFunctions = {
\"conditional\": parse_conditional,
\"or\": parse_or,
\"and\": parse_and,
\"equality\": parse_equality,
\"rel\": parse_rel,
\"sum\": parse_sum,
\"product\": parse_product,
\"not\": parse_not,
\"primary\": parse_primary,
\"group\": parse_group,
\"literal\": parse_literal,
\"boolean\": parse_boolean,
\"number\": parse_number,
\"hex\": parse_hex,
\"string\": parse_string,
\"array\": parse_array,
\"values\": parse_values,
\"object\": parse_object,
\"keyvalue\": parse_keyvalue,
\"keyvalues\": parse_keyvalues,
\"ref\": parse_ref,
\"id\": parse_id,
\"property\": parse_property,
\"slashProperty\": parse_slashProperty,
\"s\": parse_s,
\"path\": parse_path,
\"root\": parse_root,
\"step\": parse_step,
\"implicitDotRoot\": parse_implicitDotRoot,
\"explicitDotRoot\": parse_explicitDotRoot,
\"dotStep\": parse_dotStep,
\"noDotStep\": parse_noDotStep
};
if (startRule !== undefined) {
if (parseFunctions[startRule] === undefined) {
throw new Error(\"Invalid rule name: \" + quote(startRule) + \".\");
}
} else {
startRule = \"conditional\";
}
var pos = 0;
var reportFailures = 0;
var rightmostFailuresPos = 0;
var rightmostFailuresExpected = [];
function padLeft(input, padding, length) {
var result = input;
var padLength = length - input.length;
for (var i = 0; i < padLength; i++) {
result = padding + result;
}
return result;
}
function escape(ch) {
var charCode = ch.charCodeAt(0);
var escapeChar;
var length;
if (charCode <= 0xFF) {
escapeChar = 'x';
length = 2;
} else {
escapeChar = 'u';
length = 4;
}
return '\\\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
}
function matchFailed(failure) {
if (pos < rightmostFailuresPos) {
return;
}
if (pos > rightmostFailuresPos) {
rightmostFailuresPos = pos;
rightmostFailuresExpected = [];
}
rightmostFailuresExpected.push(failure);
}
function parse_conditional() {
var result0, result1, result2, result3, result4, result5;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_or();
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = \"?\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"?\\\"\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = \":\";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed(\"\\\":\\\"\");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = \"?\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"?\\\"\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = \":\";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed(\"\\\":\\\"\");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {
return [b, c];
})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, e, args) {
while (args.length > 0) {
e = expr(\"?:\", [e].concat(args.pop()));
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_or() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_and();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === \"or\") {
result2 = \"or\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"or\\\"\");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === \"or\") {
result2 = \"or\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"or\\\"\");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_and() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_equality();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 3) === \"and\") {
result2 = \"and\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"and\\\"\");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 3) === \"and\") {
result2 = \"and\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"and\\\"\");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_equality() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_rel();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === \"==\") {
result2 = \"==\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"==\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \"!=\") {
result2 = \"!=\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"!=\\\"\");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === \"==\") {
result2 = \"==\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"==\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \"!=\") {
result2 = \"!=\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"!=\\\"\");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_rel() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_sum();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === \"<=\") {
result2 = \"<=\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"<=\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \">=\") {
result2 = \">=\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\">=\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = \"<\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"<\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = \">\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\">\\\"\");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === \"<=\") {
result2 = \"<=\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"<=\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \">=\") {
result2 = \">=\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\">=\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = \"<\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"<\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = \">\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\">\\\"\");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_sum() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_product();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = \"+\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"+\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \"-\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"-\\\"\");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = \"+\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"+\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \"-\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"-\\\"\");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_product() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_not();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = \"*\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"*\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \"div\") {
result2 = \"div\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"div\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \"mod\") {
result2 = \"mod\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"mod\\\"\");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = \"*\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"*\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \"div\") {
result2 = \"div\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"div\\\"\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \"mod\") {
result2 = \"mod\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"mod\\\"\");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinLeft(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_not() {
var result0, result1, result2;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = [];
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = \"!\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"!\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = \"~\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"~\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = \"+\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"+\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \"-\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"-\\\"\");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
while (result1 !== null) {
result0.push(result1);
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = \"!\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"!\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = \"~\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"~\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = \"+\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"+\\\"\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \"-\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"-\\\"\");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) {
return op;
})(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
}
if (result0 !== null) {
result1 = parse_primary();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, ops, b) {
return unaryRight(ops, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_primary() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_group();
if (result1 === null) {
result1 = parse_literal();
if (result1 === null) {
result1 = parse_path();
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_group() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = \"(\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"(\\\"\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = \")\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\")\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_literal() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_boolean();
if (result1 === null) {
result1 = parse_number();
if (result1 === null) {
result1 = parse_string();
if (result1 === null) {
result1 = parse_array();
if (result1 === null) {
result1 = parse_object();
}
}
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_boolean() {
var result0;
var pos0;
pos0 = pos;
if (input.substr(pos, 4) === \"true\") {
result0 = \"true\";
pos += 4;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"true\\\"\");
}
}
if (result0 === null) {
if (input.substr(pos, 5) === \"false\") {
result0 = \"false\";
pos += 5;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"false\\\"\");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a == \"true\";
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_number() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\"[0-9]\");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\"[0-9]\");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
pos2 = pos;
if (input.charCodeAt(pos) === 46) {
result1 = \".\";
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\"\\\".\\\"\");
}
}
if (result1 !== null) {
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"[0-9]\");
}
}
if (result3 !== null) {
result2 = [];
while (result3 !== null) {
result2.push(result3);
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"[0-9]\");
}
}
}
} else {
result2 = null;
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos2;
}
} else {
result1 = null;
pos = pos2;
}
result1 = result1 !== null ? result1: \"\";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return parseFloat(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_hex() {
var result0;
if (/^[a-fA-F0-9]/.test(input.charAt(pos))) {
result0 = input.charAt(pos);
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"[a-fA-F0-9]\");
}
}
return result0;
}
function parse_string() {
var result0, result1, result2, result3, result4, result5, result6, result7;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 34) {
result0 = \"\\\"\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\"\\\"\");
}
}
if (result0 !== null) {
result1 = [];
if (/^[\\0-!#-\\\\^-\\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"[\\\\0-!#-\\\\\\\\^-\\\\uFFFF]\");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = \"\\\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\\\\\"\");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = \"\\\"\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\"\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = \"\\\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\\\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = \"/\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"/\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = \"b\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"b\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = \"f\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"f\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = \"n\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"n\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = \"r\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"r\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = \"t\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"t\\\"\");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = \"u\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"u\\\"\");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[\\0-!#-\\\\^-\\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"[\\\\0-!#-\\\\\\\\^-\\\\uFFFF]\");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = \"\\\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\\\\\"\");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = \"\\\"\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\"\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = \"\\\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\\\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = \"/\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"/\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = \"b\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"b\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = \"f\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"f\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = \"n\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"n\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = \"r\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"r\\\"\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = \"t\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"t\\\"\");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = \"u\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"u\\\"\");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
}
if (result1 !== null) {
if (input.charCodeAt(pos) === 34) {
result2 = \"\\\"\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"\\\\\\\"\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return JSON.parse(toString(a));
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_array() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = \"[\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"[\\\"\");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = \"]\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"]\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"array\", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_values() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_conditional();
result0 = result0 !== null ? result0: \"\";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \",\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\",\\\"\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \",\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\",\\\"\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, args) {
if (first != \"\") {
args.unshift(first);
}
return args;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_object() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = \"{\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"{\\\"\");
}
}
if (result0 !== null) {
result1 = parse_keyvalues();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = \"}\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"}\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"object\", a);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalue() {
var result0, result1, result2, result3, result4;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_string();
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
if (input.charCodeAt(pos) === 58) {
result3 = \":\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\"\\\":\\\"\");
}
}
if (result3 !== null) {
result4 = parse_conditional();
if (result4 !== null) {
result0 = [result0, result1, result2, result3, result4];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return [a, b];
})(pos0, result0[1], result0[4]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalues() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_keyvalue();
result0 = result0 !== null ? result0: \"\";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \",\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\",\\\"\");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \",\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\",\\\"\");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {
return b;
})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, rest) {
if (first) {
rest.unshift(first);
}
return rest;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_ref() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.substr(pos, 2) === \"//\") {
result0 = \"//\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"//\\\"\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 47) {
result0 = \"/\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"/\\\"\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 36) {
result0 = \"$\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"$\\\"\");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === \"**\") {
result0 = \"**\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"**\\\"\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = \"*\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"*\\\"\");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === \"..\") {
result0 = \"..\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"..\\\"\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 46) {
result0 = \".\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\".\\\"\");
}
}
}
}
}
}
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
result1 = result1 !== null ? result1: \"\";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
e = expr(a);
if (b) {
b.args.unshift(e);
e = b;
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"ref\", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_id() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\"[a-z_]\");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\"[a-z_]\");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
result1 = [];
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"[a-z_0-9]\");
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"[a-z_0-9]\");
}
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return a.join('') + b.join('');
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_property() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = \"/\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"/\\\"\");
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = \"{\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"{\\\"\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = \"}\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"}\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"{}\", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = \"[\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"[\\\"\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = \"]\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"]\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"[]\", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_slashProperty() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_number();
if (result0 === null) {
result0 = parse_string();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"/\", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.substr(pos, 2) === \"..\") {
result0 = \"..\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"..\\\"\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = \"*\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"*\\\"\");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(a, []);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_s() {
var result0, result1;
var pos0;
reportFailures++;
pos0 = pos;
result0 = [];
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\"[ ]\");
}
}
while (result1 !== null) {
result0.push(result1);
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\"[ ]\");
}
}
}
if (result0 !== null) {
result0 = (function(offset) {
return '';
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
reportFailures--;
if (reportFailures === 0 && result0 === null) {
matchFailed(\"space\");
}
return result0;
}
function parse_path() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_root();
if (result0 !== null) {
result1 = [];
result2 = parse_step();
while (result2 !== null) {
result1.push(result2);
result2 = parse_step();
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_root() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_implicitDotRoot();
if (result0 !== null) {
result1 = parse_dotStep();
result1 = result1 !== null ? result1: \"\";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
return joinPath(a, b);
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_explicitDotRoot();
}
return result0;
}
function parse_step() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = \".\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\".\\\"\");
}
}
if (result0 !== null) {
result1 = parse_dotStep();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return a;
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_noDotStep();
}
return result0;
}
function parse_implicitDotRoot() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = \"/\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"/\\\"\");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr(\"root\");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 64) {
result0 = \"@\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"@\\\"\");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr(\"this\");
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = \".\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\".\\\"\");
}
}
if (result0 !== null) {
if (input.charCodeAt(pos) === 46) {
result2 = \".\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\".\\\"\");
}
}
if (result2 !== null) {
result1 = [];
while (result2 !== null) {
result1.push(result2);
if (input.charCodeAt(pos) === 46) {
result2 = \".\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\".\\\"\");
}
}
}
} else {
result1 = null;
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"ancestor\", [a.length]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_explicitDotRoot() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"ref\", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = \"*\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"*\\\"\");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr(\"values\", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_dotStep() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_string();
if (result0 === null) {
result0 = parse_number();
}
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"get\", [a]);
})(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = \"*\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"*\\\"\");
}
}
if (result0 !== null) {
result0 = (function(offset) {
return expr(\"values\", []);
})(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_noDotStep() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = \"{\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"{\\\"\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = \"}\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"}\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"eval\", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = \"[\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"[\\\"\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = \"]\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"]\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"pred\", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = \"(\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\"\\\"(\\\"\");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = \")\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\"\\\")\\\"\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) {
return expr(\"call\", [a]);
})(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function cleanupExpected(expected) {
expected.sort();
var lastExpected = null;
var cleanExpected = [];
for (var i = 0; i < expected.length; i++) {
if (expected[i] !== lastExpected) {
cleanExpected.push(expected[i]);
lastExpected = expected[i];
}
}
return cleanExpected;
}
function computeErrorPosition() {
/*
* The first idea was to use |String.split| to break the input up to the
* error position along newlines and derive the line and column from
* there. However IE's |split| implementation is so broken that it was
* enough to prevent it.
*/
var line = 1;
var column = 1;
var seenCR = false;
for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
var ch = input.charAt(i);
if (ch === \"
\") {
if (!seenCR) {
line++;
}
column = 1;
seenCR = false;
} else if (ch === \"
\" || ch === \"\\u2028\" || ch === \"\\u2029\") {
line++;
column = 1;
seenCR = true;
} else {
column++;
seenCR = false;
}
}
return {
line: line,
column: column
};
}
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e, array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++) array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
var result = parseFunctions[startRule]();
/*
* The parser is now in one of the following three states:
*
* 1. The parser successfully parsed the whole input.
*
* - |result !== null|
* - |pos === input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 2. The parser successfully parsed only a part of the input.
*
* - |result !== null|
* - |pos < input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 3. The parser did not successfully parse any part of the input.
*
* - |result === null|
* - |pos === 0|
* - |rightmostFailuresExpected| contains at least one failure
*
* All code following this comment (including called functions) must
* handle these states.
*/
if (result === null || pos !== input.length) {
var offset = Math.max(pos, rightmostFailuresPos);
var found = offset < input.length ? input.charAt(offset) : null;
var errorPosition = computeErrorPosition();
throw new this.SyntaxError(cleanupExpected(rightmostFailuresExpected), found, offset, errorPosition.line, errorPosition.column);
}
return result;
},
toSource: function() {
return this._source;
},
SyntaxError: function(expected, found, offset, line, column) {
function buildMessage(expected, found) {
var expectedHumanized, foundHumanized;
switch (expected.length) {
case 0:
expectedHumanized = \"end of input\";
break;
case 1:
expectedHumanized = expected[0];
break;
default:
expectedHumanized = expected.slice(0, expected.length - 1).join(\", \") + \" or \" + expected[expected.length - 1];
}
foundHumanized = found ? quote(found) : \"end of input\";
return \"Expected \" + expectedHumanized + \" but \" + foundHumanized + \" found.\";
}
this.name = \"SyntaxError\";
this.expected = expected;
this.found = found;
this.message = buildMessage(expected, found);
this.offset = offset;
this.line = line;
this.column = column;
},
_source: \"(function(){
/*
* Generated by PEG.js 0.7.0.
*
* http://pegjs.majda.cz/
*/
function quote(s) {
/*
* ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a
* string literal except for the closing quote character, backslash,
* carriage return, line separator, paragraph separator, and line feed.
* Any character may appear in the form of an escape sequence.
*
* For portability, we also escape escape all control and non-ASCII
* characters. Note that \\\"\\\\0\\\" and \\\"\\\\v\\\" escape sequences are not used
* because JSHint does not like the first and IE the second.
*/
return '\\\"' + s
.replace(/\\\\\\\\/g, '\\\\\\\\\\\\\\\\') // backslash
.replace(/\\\"/g, '\\\\\\\\\\\"') // closing quote character
.replace(/\\\\x08/g, '\\\\\\\\b') // backspace
.replace(/\\\\t/g, '\\\\\\\\t') // horizontal tab
.replace(/\\
/g, '\\\\\\
') // line feed
.replace(/\\\\f/g, '\\\\\\\\f') // form feed
.replace(/\\
/g, '\\\\\\
') // carriage return
.replace(/[\\\\x00-\\\\x07\\\\x0B\\\\x0E-\\\\x1F\\\\x80-\\\\uFFFF]/g, escape)
+ '\\\"';
}
var result = {
/*
* Parses the input with a generated parser. If the parsing is successfull,
* returns a value explicitly or implicitly specified by the grammar from
* which the parser was generated (see |PEG.buildParser|). If the parsing is
* unsuccessful, throws |PEG.parser.SyntaxError| describing the error.
*/
parse: function(input, startRule) {
var parseFunctions = {
\\\"conditional\\\": parse_conditional,
\\\"or\\\": parse_or,
\\\"and\\\": parse_and,
\\\"equality\\\": parse_equality,
\\\"rel\\\": parse_rel,
\\\"sum\\\": parse_sum,
\\\"product\\\": parse_product,
\\\"not\\\": parse_not,
\\\"primary\\\": parse_primary,
\\\"group\\\": parse_group,
\\\"literal\\\": parse_literal,
\\\"boolean\\\": parse_boolean,
\\\"number\\\": parse_number,
\\\"hex\\\": parse_hex,
\\\"string\\\": parse_string,
\\\"array\\\": parse_array,
\\\"values\\\": parse_values,
\\\"object\\\": parse_object,
\\\"keyvalue\\\": parse_keyvalue,
\\\"keyvalues\\\": parse_keyvalues,
\\\"ref\\\": parse_ref,
\\\"id\\\": parse_id,
\\\"property\\\": parse_property,
\\\"slashProperty\\\": parse_slashProperty,
\\\"s\\\": parse_s,
\\\"path\\\": parse_path,
\\\"root\\\": parse_root,
\\\"step\\\": parse_step,
\\\"implicitDotRoot\\\": parse_implicitDotRoot,
\\\"explicitDotRoot\\\": parse_explicitDotRoot,
\\\"dotStep\\\": parse_dotStep,
\\\"noDotStep\\\": parse_noDotStep
};
if (startRule !== undefined) {
if (parseFunctions[startRule] === undefined) {
throw new Error(\\\"Invalid rule name: \\\" + quote(startRule) + \\\".\\\");
}
} else {
startRule = \\\"conditional\\\";
}
var pos = 0;
var reportFailures = 0;
var rightmostFailuresPos = 0;
var rightmostFailuresExpected = [];
function padLeft(input, padding, length) {
var result = input;
var padLength = length - input.length;
for (var i = 0; i < padLength; i++) {
result = padding + result;
}
return result;
}
function escape(ch) {
var charCode = ch.charCodeAt(0);
var escapeChar;
var length;
if (charCode <= 0xFF) {
escapeChar = 'x';
length = 2;
} else {
escapeChar = 'u';
length = 4;
}
return '\\\\\\\\' + escapeChar + padLeft(charCode.toString(16).toUpperCase(), '0', length);
}
function matchFailed(failure) {
if (pos < rightmostFailuresPos) {
return;
}
if (pos > rightmostFailuresPos) {
rightmostFailuresPos = pos;
rightmostFailuresExpected = [];
}
rightmostFailuresExpected.push(failure);
}
function parse_conditional() {
var result0, result1, result2, result3, result4, result5;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_or();
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = \\\"?\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"?\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = \\\":\\\";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\":\\\\\\\"\\\");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {return [b,c];})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 63) {
result2 = \\\"?\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"?\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
if (input.charCodeAt(pos) === 58) {
result4 = \\\":\\\";
pos++;
} else {
result4 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\":\\\\\\\"\\\");
}
}
if (result4 !== null) {
result5 = parse_conditional();
if (result5 !== null) {
result2 = [result2, result3, result4, result5];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b, c) {return [b,c];})(pos2, result2[1], result2[3]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, e, args) {
while (args.length > 0) {
e = expr(\\\"?:\\\", [e].concat(args.pop()));
}
return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_or() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_and();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === \\\"or\\\") {
result2 = \\\"or\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"or\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === \\\"or\\\") {
result2 = \\\"or\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"or\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_and();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return joinLeft(a,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_and() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_equality();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 3) === \\\"and\\\") {
result2 = \\\"and\\\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"and\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 3) === \\\"and\\\") {
result2 = \\\"and\\\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"and\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_equality();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return joinLeft(a,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_equality() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_rel();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === \\\"==\\\") {
result2 = \\\"==\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"==\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \\\"!=\\\") {
result2 = \\\"!=\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"!=\\\\\\\"\\\");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === \\\"==\\\") {
result2 = \\\"==\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"==\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \\\"!=\\\") {
result2 = \\\"!=\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"!=\\\\\\\"\\\");
}
}
}
if (result2 !== null) {
result3 = parse_rel();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return joinLeft(a,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_rel() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_sum();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.substr(pos, 2) === \\\"<=\\\") {
result2 = \\\"<=\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"<=\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \\\">=\\\") {
result2 = \\\">=\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\">=\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = \\\"<\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"<\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = \\\">\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\">\\\\\\\"\\\");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.substr(pos, 2) === \\\"<=\\\") {
result2 = \\\"<=\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"<=\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 2) === \\\">=\\\") {
result2 = \\\">=\\\";
pos += 2;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\">=\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 60) {
result2 = \\\"<\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"<\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 62) {
result2 = \\\">\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\">\\\\\\\"\\\");
}
}
}
}
}
if (result2 !== null) {
result3 = parse_sum();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return joinLeft(a,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_sum() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_product();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = \\\"+\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"+\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \\\"-\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"-\\\\\\\"\\\");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 43) {
result2 = \\\"+\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"+\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \\\"-\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"-\\\\\\\"\\\");
}
}
}
if (result2 !== null) {
result3 = parse_product();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return joinLeft(a,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_product() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
result0 = parse_not();
if (result0 !== null) {
result1 = [];
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = \\\"*\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"*\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \\\"div\\\") {
result2 = \\\"div\\\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"div\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \\\"mod\\\") {
result2 = \\\"mod\\\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"mod\\\\\\\"\\\");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
if (input.charCodeAt(pos) === 42) {
result2 = \\\"*\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"*\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \\\"div\\\") {
result2 = \\\"div\\\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"div\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.substr(pos, 3) === \\\"mod\\\") {
result2 = \\\"mod\\\";
pos += 3;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"mod\\\\\\\"\\\");
}
}
}
}
if (result2 !== null) {
result3 = parse_not();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return joinLeft(a,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_not() {
var result0, result1, result2;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = [];
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = \\\"!\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"!\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = \\\"~\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"~\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = \\\"+\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"+\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \\\"-\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"-\\\\\\\"\\\");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) { return op; })(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
while (result1 !== null) {
result0.push(result1);
pos2 = pos;
pos3 = pos;
result1 = parse_s();
if (result1 !== null) {
if (input.charCodeAt(pos) === 33) {
result2 = \\\"!\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"!\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 126) {
result2 = \\\"~\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"~\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 43) {
result2 = \\\"+\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"+\\\\\\\"\\\");
}
}
if (result2 === null) {
if (input.charCodeAt(pos) === 45) {
result2 = \\\"-\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"-\\\\\\\"\\\");
}
}
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos3;
}
} else {
result1 = null;
pos = pos3;
}
if (result1 !== null) {
result1 = (function(offset, op) { return op; })(pos2, result1[1]);
}
if (result1 === null) {
pos = pos2;
}
}
if (result0 !== null) {
result1 = parse_primary();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, ops, b) { return unaryRight(ops,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_primary() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_group();
if (result1 === null) {
result1 = parse_literal();
if (result1 === null) {
result1 = parse_path();
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return a; })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_group() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = \\\"(\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"(\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = \\\")\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\")\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return a; })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_literal() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_boolean();
if (result1 === null) {
result1 = parse_number();
if (result1 === null) {
result1 = parse_string();
if (result1 === null) {
result1 = parse_array();
if (result1 === null) {
result1 = parse_object();
}
}
}
}
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return a; })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_boolean() {
var result0;
var pos0;
pos0 = pos;
if (input.substr(pos, 4) === \\\"true\\\") {
result0 = \\\"true\\\";
pos += 4;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"true\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.substr(pos, 5) === \\\"false\\\") {
result0 = \\\"false\\\";
pos += 5;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"false\\\\\\\"\\\");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) { return a == \\\"true\\\"; })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_number() {
var result0, result1, result2, result3;
var pos0, pos1, pos2;
pos0 = pos;
pos1 = pos;
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\\\"[0-9]\\\");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[0-9]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\\\"[0-9]\\\");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
pos2 = pos;
if (input.charCodeAt(pos) === 46) {
result1 = \\\".\\\";
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\".\\\\\\\"\\\");
}
}
if (result1 !== null) {
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"[0-9]\\\");
}
}
if (result3 !== null) {
result2 = [];
while (result3 !== null) {
result2.push(result3);
if (/^[0-9]/.test(input.charAt(pos))) {
result3 = input.charAt(pos);
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"[0-9]\\\");
}
}
}
} else {
result2 = null;
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = pos2;
}
} else {
result1 = null;
pos = pos2;
}
result1 = result1 !== null ? result1 : \\\"\\\";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return parseFloat(toString(a)); })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_hex() {
var result0;
if (/^[a-fA-F0-9]/.test(input.charAt(pos))) {
result0 = input.charAt(pos);
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"[a-fA-F0-9]\\\");
}
}
return result0;
}
function parse_string() {
var result0, result1, result2, result3, result4, result5, result6, result7;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 34) {
result0 = \\\"\\\\\\\"\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = [];
if (/^[\\\\0-!#-\\\\\\\\^-\\\\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"[\\\\\\\\0-!#-\\\\\\\\\\\\\\\\^-\\\\\\\\uFFFF]\\\");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = \\\"\\\\\\\\\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\"\\\");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = \\\"\\\\\\\"\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = \\\"\\\\\\\\\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = \\\"/\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"/\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = \\\"b\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"b\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = \\\"f\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"f\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = \\\"n\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"n\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = \\\"r\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"r\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = \\\"t\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"t\\\\\\\"\\\");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = \\\"u\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"u\\\\\\\"\\\");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[\\\\0-!#-\\\\\\\\^-\\\\uFFFF]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"[\\\\\\\\0-!#-\\\\\\\\\\\\\\\\^-\\\\\\\\uFFFF]\\\");
}
}
if (result2 === null) {
pos2 = pos;
if (input.charCodeAt(pos) === 92) {
result2 = \\\"\\\\\\\\\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\"\\\");
}
}
if (result2 !== null) {
if (input.charCodeAt(pos) === 34) {
result3 = \\\"\\\\\\\"\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 92) {
result3 = \\\"\\\\\\\\\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 47) {
result3 = \\\"/\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"/\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 98) {
result3 = \\\"b\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"b\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 102) {
result3 = \\\"f\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"f\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 110) {
result3 = \\\"n\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"n\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 114) {
result3 = \\\"r\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"r\\\\\\\"\\\");
}
}
if (result3 === null) {
if (input.charCodeAt(pos) === 116) {
result3 = \\\"t\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"t\\\\\\\"\\\");
}
}
if (result3 === null) {
pos3 = pos;
if (input.charCodeAt(pos) === 117) {
result3 = \\\"u\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"u\\\\\\\"\\\");
}
}
if (result3 !== null) {
result4 = parse_hex();
if (result4 !== null) {
result5 = parse_hex();
if (result5 !== null) {
result6 = parse_hex();
if (result6 !== null) {
result7 = parse_hex();
if (result7 !== null) {
result3 = [result3, result4, result5, result6, result7];
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
} else {
result3 = null;
pos = pos3;
}
}
}
}
}
}
}
}
}
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos2;
}
} else {
result2 = null;
pos = pos2;
}
}
}
if (result1 !== null) {
if (input.charCodeAt(pos) === 34) {
result2 = \\\"\\\\\\\"\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"\\\\\\\\\\\\\\\"\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return JSON.parse(toString(a)); })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_array() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = \\\"[\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"[\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = \\\"]\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"]\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"array\\\", a); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_values() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_conditional();
result0 = result0 !== null ? result0 : \\\"\\\";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \\\",\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\",\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {return b;})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \\\",\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\",\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_conditional();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {return b;})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, args) {
if (first != \\\"\\\") { args.unshift(first); } return args;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_object() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = \\\"{\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"{\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_keyvalues();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = \\\"}\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"}\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"object\\\", a); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalue() {
var result0, result1, result2, result3, result4;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_s();
if (result0 !== null) {
result1 = parse_string();
if (result1 !== null) {
result2 = parse_s();
if (result2 !== null) {
if (input.charCodeAt(pos) === 58) {
result3 = \\\":\\\";
pos++;
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\":\\\\\\\"\\\");
}
}
if (result3 !== null) {
result4 = parse_conditional();
if (result4 !== null) {
result0 = [result0, result1, result2, result3, result4];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return [a,b]; })(pos0, result0[1], result0[4]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_keyvalues() {
var result0, result1, result2, result3;
var pos0, pos1, pos2, pos3;
pos0 = pos;
pos1 = pos;
result0 = parse_keyvalue();
result0 = result0 !== null ? result0 : \\\"\\\";
if (result0 !== null) {
result1 = [];
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \\\",\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\",\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {return b;})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
while (result2 !== null) {
result1.push(result2);
pos2 = pos;
pos3 = pos;
if (input.charCodeAt(pos) === 44) {
result2 = \\\",\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\",\\\\\\\"\\\");
}
}
if (result2 !== null) {
result3 = parse_keyvalue();
if (result3 !== null) {
result2 = [result2, result3];
} else {
result2 = null;
pos = pos3;
}
} else {
result2 = null;
pos = pos3;
}
if (result2 !== null) {
result2 = (function(offset, b) {return b;})(pos2, result2[1]);
}
if (result2 === null) {
pos = pos2;
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, first, rest) {
if (first) { rest.unshift(first); } return rest;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_ref() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.substr(pos, 2) === \\\"//\\\") {
result0 = \\\"//\\\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"//\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 47) {
result0 = \\\"/\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"/\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 36) {
result0 = \\\"$\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"$\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === \\\"**\\\") {
result0 = \\\"**\\\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"**\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = \\\"*\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"*\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.substr(pos, 2) === \\\"..\\\") {
result0 = \\\"..\\\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"..\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 46) {
result0 = \\\".\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\".\\\\\\\"\\\");
}
}
}
}
}
}
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
result1 = result1 !== null ? result1 : \\\"\\\";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
e = expr(a); if (b) { b.args.unshift(e); e = b; } return e;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"ref\\\", [a]); })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_id() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\\\"[a-z_]\\\");
}
}
if (result1 !== null) {
result0 = [];
while (result1 !== null) {
result0.push(result1);
if (/^[a-z_]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\\\"[a-z_]\\\");
}
}
}
} else {
result0 = null;
}
if (result0 !== null) {
result1 = [];
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"[a-z_0-9]\\\");
}
}
while (result2 !== null) {
result1.push(result2);
if (/^[a-z_0-9]/.test(input.charAt(pos))) {
result2 = input.charAt(pos);
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"[a-z_0-9]\\\");
}
}
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return a.join('') + b.join(''); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_property() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = \\\"/\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"/\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_slashProperty();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return a; })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = \\\"{\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"{\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = \\\"}\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"}\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"{}\\\", [a]); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = \\\"[\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"[\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = \\\"]\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"]\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"[]\\\", [a]); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_slashProperty() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_number();
if (result0 === null) {
result0 = parse_string();
}
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"/\\\", [a]); })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.substr(pos, 2) === \\\"..\\\") {
result0 = \\\"..\\\";
pos += 2;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"..\\\\\\\"\\\");
}
}
if (result0 === null) {
if (input.charCodeAt(pos) === 42) {
result0 = \\\"*\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"*\\\\\\\"\\\");
}
}
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(a, []); })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_s() {
var result0, result1;
var pos0;
reportFailures++;
pos0 = pos;
result0 = [];
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\\\"[ ]\\\");
}
}
while (result1 !== null) {
result0.push(result1);
if (/^[ ]/.test(input.charAt(pos))) {
result1 = input.charAt(pos);
pos++;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed(\\\"[ ]\\\");
}
}
}
if (result0 !== null) {
result0 = (function(offset) { return ''; })(pos0);
}
if (result0 === null) {
pos = pos0;
}
reportFailures--;
if (reportFailures === 0 && result0 === null) {
matchFailed(\\\"space\\\");
}
return result0;
}
function parse_path() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_root();
if (result0 !== null) {
result1 = [];
result2 = parse_step();
while (result2 !== null) {
result1.push(result2);
result2 = parse_step();
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) {
while (b.length) {
a = joinPath(a, b.shift());
}
return a;
})(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
return result0;
}
function parse_root() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
result0 = parse_implicitDotRoot();
if (result0 !== null) {
result1 = parse_dotStep();
result1 = result1 !== null ? result1 : \\\"\\\";
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a, b) { return joinPath(a,b); })(pos0, result0[0], result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_explicitDotRoot();
}
return result0;
}
function parse_step() {
var result0, result1;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = \\\".\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\".\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_dotStep();
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return a; })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
result0 = parse_noDotStep();
}
return result0;
}
function parse_implicitDotRoot() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
if (input.charCodeAt(pos) === 47) {
result0 = \\\"/\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"/\\\\\\\"\\\");
}
}
if (result0 !== null) {
result0 = (function(offset) { return expr(\\\"root\\\"); })(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 64) {
result0 = \\\"@\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"@\\\\\\\"\\\");
}
}
if (result0 !== null) {
result0 = (function(offset) { return expr(\\\"this\\\"); })(pos0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 46) {
result0 = \\\".\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\".\\\\\\\"\\\");
}
}
if (result0 !== null) {
if (input.charCodeAt(pos) === 46) {
result2 = \\\".\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\".\\\\\\\"\\\");
}
}
if (result2 !== null) {
result1 = [];
while (result2 !== null) {
result1.push(result2);
if (input.charCodeAt(pos) === 46) {
result2 = \\\".\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\".\\\\\\\"\\\");
}
}
}
} else {
result1 = null;
}
if (result1 !== null) {
result0 = [result0, result1];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"ancestor\\\", [a.length]); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function parse_explicitDotRoot() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"ref\\\", [a]); })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = \\\"*\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"*\\\\\\\"\\\");
}
}
if (result0 !== null) {
result0 = (function(offset) { return expr(\\\"values\\\", []); })(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_dotStep() {
var result0;
var pos0;
pos0 = pos;
result0 = parse_id();
if (result0 === null) {
result0 = parse_string();
if (result0 === null) {
result0 = parse_number();
}
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"get\\\", [a]); })(pos0, result0);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
if (input.charCodeAt(pos) === 42) {
result0 = \\\"*\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"*\\\\\\\"\\\");
}
}
if (result0 !== null) {
result0 = (function(offset) { return expr(\\\"values\\\", []); })(pos0);
}
if (result0 === null) {
pos = pos0;
}
}
return result0;
}
function parse_noDotStep() {
var result0, result1, result2;
var pos0, pos1;
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 123) {
result0 = \\\"{\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"{\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 125) {
result2 = \\\"}\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"}\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"eval\\\", [a]); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 91) {
result0 = \\\"[\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"[\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_conditional();
if (result1 !== null) {
if (input.charCodeAt(pos) === 93) {
result2 = \\\"]\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"]\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"pred\\\", [a]); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
if (result0 === null) {
pos0 = pos;
pos1 = pos;
if (input.charCodeAt(pos) === 40) {
result0 = \\\"(\\\";
pos++;
} else {
result0 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\"(\\\\\\\"\\\");
}
}
if (result0 !== null) {
result1 = parse_values();
if (result1 !== null) {
if (input.charCodeAt(pos) === 41) {
result2 = \\\")\\\";
pos++;
} else {
result2 = null;
if (reportFailures === 0) {
matchFailed(\\\"\\\\\\\")\\\\\\\"\\\");
}
}
if (result2 !== null) {
result0 = [result0, result1, result2];
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
} else {
result0 = null;
pos = pos1;
}
if (result0 !== null) {
result0 = (function(offset, a) { return expr(\\\"call\\\", [a]); })(pos0, result0[1]);
}
if (result0 === null) {
pos = pos0;
}
}
}
return result0;
}
function cleanupExpected(expected) {
expected.sort();
var lastExpected = null;
var cleanExpected = [];
for (var i = 0; i < expected.length; i++) {
if (expected[i] !== lastExpected) {
cleanExpected.push(expected[i]);
lastExpected = expected[i];
}
}
return cleanExpected;
}
function computeErrorPosition() {
/*
* The first idea was to use |String.split| to break the input up to the
* error position along newlines and derive the line and column from
* there. However IE's |split| implementation is so broken that it was
* enough to prevent it.
*/
var line = 1;
var column = 1;
var seenCR = false;
for (var i = 0; i < Math.max(pos, rightmostFailuresPos); i++) {
var ch = input.charAt(i);
if (ch === \\\"\\
\\\") {
if (!seenCR) { line++; }
column = 1;
seenCR = false;
} else if (ch === \\\"\\
\\\" || ch === \\\"\\\\u2028\\\" || ch === \\\"\\\\u2029\\\") {
line++;
column = 1;
seenCR = true;
} else {
column++;
seenCR = false;
}
}
return { line: line, column: column };
}
// shorthand to create a new expression
function expr(op, args) {
return new glass.Expression(op, args);
}
// left associates operations
function joinLeft(e, arrayOfOps) {
while (arrayOfOps.length > 0) {
array = arrayOfOps.shift();
e = expr(array[0], [e,array[1]]);
}
return e;
}
function unaryRight(ops, e) {
while (ops.length > 0) {
e = expr(ops.pop(), [e]);
}
return e;
}
function toString(array) {
if (Array.isArray(array)) {
for (var i = 0; i < array.length; i++)
array[i] = toString(array[i]);
return array.join('');
}
return array;
}
function joinPath(left, right) {
if (right) {
right.args.unshift(left);
left = right;
}
return left;
}
var result = parseFunctions[startRule]();
/*
* The parser is now in one of the following three states:
*
* 1. The parser successfully parsed the whole input.
*
* - |result !== null|
* - |pos === input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 2. The parser successfully parsed only a part of the input.
*
* - |result !== null|
* - |pos < input.length|
* - |rightmostFailuresExpected| may or may not contain something
*
* 3. The parser did not successfully parse any part of the input.
*
* - |result === null|
* - |pos === 0|
* - |rightmostFailuresExpected| contains at least one failure
*
* All code following this comment (including called functions) must
* handle these states.
*/
if (result === null || pos !== input.length) {
var offset = Math.max(pos, rightmostFailuresPos);
var found = offset < input.length ? input.charAt(offset) : null;
var errorPosition = computeErrorPosition();
throw new this.SyntaxError(
cleanupExpected(rightmostFailuresExpected),
found,
offset,
errorPosition.line,
errorPosition.column
);
}
return result;
},
/* Returns the parser source code. */
toSource: function() { return this._source; }
};
/* Thrown when a parser encounters a syntax error. */
result.SyntaxError = function(expected, found, offset, line, column) {
function buildMessage(expected, found) {
var expectedHumanized, foundHumanized;
switch (expected.length) {
case 0:
expectedHumanized = \\\"end of input\\\";
break;
case 1:
expectedHumanized = expected[0];
break;
default:
expectedHumanized = expected.slice(0, expected.length - 1).join(\\\", \\\")
+ \\\" or \\\"
+ expected[expected.length - 1];
}
foundHumanized = found ? quote(found) : \\\"end of input\\\";
return \\\"Expected \\\" + expectedHumanized + \\\" but \\\" + foundHumanized + \\\" found.\\\";
}
this.name = \\\"SyntaxError\\\";
this.expected = expected;
this.found = found;
this.message = buildMessage(expected, found);
this.offset = offset;
this.line = line;
this.column = column;
};
result.SyntaxError.prototype = Error.prototype;
return result;
})()\"
};
_parser._init_ = function() {
values = global.glass.values;
delete _parser._init_;
}
}).call(glass.Expression)",
"www\\js\\glass\\allTests.js": "(function() {
var global = (function() {
return this;
})();
var glass; // assigned during _init_
var glass_Expression; // assigned during _init_
var glass_JSONMergePatch; // assigned during _init_
var glass_JSONPointer; // assigned during _init_
var glass_Observable; // assigned during _init_
var glass_Component; // assigned during _init_
var allTests = this.allTests = function anonymous(callback) {
if (callback == null) {
callback = function(path, result) {
if (result == null) {
console.log(\"\\033[92mPass\\033[0m: \" + path + \"\");
} else {
console.log(\"\\033[91mFail\\033[0m: \" + path + \"\");
console.log(result.stack || result);
}
}
}
function singleTest(path, test) {
if (test == null) {
callback(path, \"test not found\");
return;
} else if (typeof test == 'object') {
for (var key in test) singleTest(path + '.' + key, test[key]);
return;
}
try {
callback(path, test());
} catch(e) {
callback(path, e);
}
}
singleTest(\"glass\", glass.test);
singleTest(\"glass.Expression\", glass_Expression.test);
singleTest(\"glass.JSONMergePatch\", glass_JSONMergePatch.test);
singleTest(\"glass.JSONPointer\", glass_JSONPointer.test);
singleTest(\"glass.Observable\", glass_Observable.test);
singleTest(\"glass.Component\", glass_Component.test);
};
allTests._init_ = function() {
glass = global.glass;
glass_Expression = global.glass.Expression;
glass_JSONMergePatch = global.glass.JSONMergePatch;
glass_JSONPointer = global.glass.JSONPointer;
glass_Observable = global.glass.Observable;
glass_Component = global.glass.Component;
delete allTests._init_;
}
allTests._init_();
glass._init_();
glass.Expression._init_();
glass.JSONMergePatch._init_();
glass.JSONPointer._init_();
glass.Observable._init_();
glass.Component._init_();
glass.Container._init_();
glass.Expression._parser._init_();
}).call(glass)",
"www/includes.html": "<script src='/js/String.js'></script>
<script src='/js/glass.js'></script>
<script src='/js/glass/Expression.js'></script>
<script src='/js/glass/JSONMergePatch.js'></script>
<script src='/js/glass/JSONPointer.js'></script>
<script src='/js/glass/Observable.js'></script>
<script src='/js/glass/Component.js'></script>
<script src='/js/glass/Container.js'></script>
<script src='/js/glass/Expression/_parser.js'></script>
<script src='/js/glass/allTests.js'></script>
",
"glass.js": "require('./www/js/String');
require('./www/js/glass');
require('./www/js/glass/Expression');
require('./www/js/glass/JSONMergePatch');
require('./www/js/glass/JSONPointer');
require('./www/js/glass/Observable');
require('./www/js/glass/Component');
require('./www/js/glass/Container');
require('./www/js/glass/Expression/_parser');
require('./www/js/glass/allTests');
"
}
} |